Home > Blockchain >  Is there command like `seq`, that performs full bash-like brace expansion to stdout?
Is there command like `seq`, that performs full bash-like brace expansion to stdout?

Time:09-30

In Bash it is often convenient to use brace expansion to nested directory trees, e.g.

mkdir -p {foo,bar}/baz{0..9}

This works until the expansion is too big for a single ARGV array. A convenient alternative would be command-x, which is like seq but accepts the same brace expansions as bash, e.g.

command-x "{a..z}/{a..z}/{a..z}" | xargs mkdir -p
command-x "{a..z}/{a..z}/{a..z}" | parallel -m mkdir -p

Before I reinvent a wheel does command-x exist?

The closest I've found so far are implementations as libraries (e.g. https://pypi.org/project/bracex/, https://pypi.org/project/braceexpand/, https://github.com/micromatch/braces). If nothing turns up I may offer a CLI interface to one of the Python ones.

CodePudding user response:

The "needs to fit in argv" limitation only applies to external commands, not to shell builtins.

Thus, the shell builtin printf is suited to purpose:

printf '%s\n' {a..z}/{a..z}/{a..z} | xargs -d $'\n' mkdir -p --

...or, better, use printf '%s\0' and xargs -0 to pass through all possible arguments (and all possible filenames), a set which includes content with literal newlines.

  • Related