more busybox ash support #19

step- opened this Issue Mar 13, 2013 · 3 comments

2 participants


I just tested it with busybox ash and it runs very smoothly, except for one thing, and two minor issues. Let me start with how I source from an ash script:

#! /bin/busybox ash
alias egrep="/bin/busybox egrep"
export BASH_SOURCE=1
. -b
tokenize | parse

Omit the export and tokenize lines if your script needs to call tokenize and parse separately. Omit -b if you don't want terse output.

Ok, one issue I found is early exit when BRIEF=1 and the shell runs with the -e flag. This is to be expected, as -e makes the script exit at the first error (non-zero exit of a command or function). However, parse_array() and parse_object() always return non-zero when BRIEF=1. So add true as the last command of those functions, it won't hurt when BRIEF=0 and it will make the script continue when BRIEF=1 and ash runs with option -e. Perhaps this point applies to bash and other shells, too. For consistency, I've also added true at the end of parse_value(), although it shouldn't be necessary.

Which brings me to a bit more serious issue. Let me show the code, and a possible fix. This is at the end of function parse_value():

#ME  ! ([ $BRIEF -eq 1 ] && ([ -z "$jpath" ] || [ $value = '""' ])) \
  ! ([ $BRIEF -eq 1 ] && ([ -z "$jpath" ] || [[ "$value" = '""' ]])) \
      && printf "[%s]\t%s\n" "$jpath" "$value"
  true #ME shouldn't be needed but just in case.

I had to replace [ $value = '""' ] with [[ "$value" = '""' ]] because when $value includes white space ash complains about an 'unknown operand'.

The last minor point is about egrep in tokenize(). I had to comment out --color=never simply because busybox egrep doesn't support option --color.

HTH, thanks for this script!




Thanks, you are definitely correct about putting "$value" in quotes.
I've fixed this, and issue #20 in version 0.1.3
I think my fix may have also fixed the early exit problem too,
can you confirm it runs in busybox/ash?

There are currently no tests for brief mode, if you care to put in a pullrequest that would be fantastic!


Yes, issue #20 is fixed in busybox/ash, and the 'unknown operand' warning has gone too. However, early exit under -e is still there. Strange, because I would have concurred with you that adding || value= should have fixed it, but it didn't. I'm keeping true as the last statement of the parse_* functions.


I've added you as a collaborator, feel free to fix that.

@step- step- pushed a commit to step-/ that referenced this issue Mar 14, 2013
stepk fix issue #19 and allow using busybox egrep 624defc
@dominictarr dominictarr closed this May 6, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment