In busybox, the default shell is ash, so some familiar tricks in bash are not available. One thing I would like to do is expand a list of letters, like {a..z}, which would expand to a b c d e f g h i j k l m n o p q r s t u v w x y z in bash. Is there another way to do this ash?

  • ash does not support brace expansion. What would you want to use this list of letters for? There might be a better way of doing it. – Kusalananda Mar 9 '18 at 17:08
  • I was walking through a list of drives, so /dev/sd* worked. However, I realized there doesn't seem to be any list expansion for letters or numbers built in, but maybe there's a better way? Could just use seq for numbers, but is there something for letters? – Paul Mar 14 '18 at 21:24

POSIXly (and with busybox) and on ASCII-based systems (I don't think busybox has ever been found on EBCDIC systems):

letters() { awk 'BEGIN{for(i=97;i<123;i++)printf "%c\n", i}'; }

Would expand to that list of letters, one per line, so assuming you've not modified $IFS,

cmd $(letters)

would be a way to pass that list as separate arguments to cmd. As you'd do with ksh93/zsh/bash's cmd {a..z}.

That's hardly an improvement over

letters() { printf '%s\n' a b c d e f g h i j k l m n o p q r s t u v w x y z; }

though. To be able to do the equivalent of foo{a..z}bar, you could define a:

letters() { printf "${1-%s\n}" a b c d e f g h i j k l m n o p q r s t u v w x y z; }

instead and call it as:

cmd $(letters 'foo%sbar\n')

You can expand on that kind of approach, by doing something like:

format() { awk -v format="$1" '{printf format, $0}' ;}

And then do:

$ seq 97 100 | format 'foo%cbar\n'
$ seq 4 | format '%04d\n'

(though the latter can also be written seq -w 0004)

seq is not a POSIX command, but busybox does come with it.

Note that busybox sh is based on ash by default but can alternatively be configured at build time to use a hush-based shell which does support brace expansion. But that's only the csh-style {a,b}, not zsh-style {1..10}, {a..z} or the more advanced forms found in ksh93/zsh/bash.


The ash shell does not support brace expansions.

Using Perl, you could do

perl -e 'print join("\n",a..z), "\n"'

where the first \n (in join()) could be replaced by the delimiter of your choice.

If you have the jot utility available,

jot -c - a z

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.