Artificial intelligent assistant

Using bash "&" operator with ";" delineator? I'm trying to write a command that's a one-line for loop containing a command that uses the & operator to put the command in the background: for dir in $(ls); do command $dir &; done Where `&` tells BASH to run `command` in the background. Yet BASH returns bash: syntax error near unexpected token `;' What's going on here? How can I use `&` in conjunction with `;`? I tried enclosing things in quotes, like `do "command $dir &"` or `do command $dir "&"` but those have unexpected results.

You don't use the `;` with '&', the '&' on its own is enough to finish the command. I believe there is currently no mention of this behaviour in the manual. Your loop would simply be:


for dir in $(ls); do command $dir & done


Additionally, you should consider using a glob instead of `$(ls)` which will fail if the filename contains whitespace. You can set `nullglob` to prevent `dir` being a `*` if there are no files:


shopt -s nullglob
for dir in *; do command $dir & done

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 4bb25193bcb46aa8708ab73d01ad9518