detach process in bash for loop

bash

Solution

Remove the semicolon after your &:

for PLT in *.png; do display ${PLT} & done

Also, using "${PLT}" is a good practice just in case your filenames have spaces in them.

Problem

I often find myself wanting to look at a bunch of plots in a directory. I typically do something like: ``` for PLT in *.png; do bash -c "display ${PLT} &" ; done ``` since ``` for PLT in *.png; do display ${PLT} & ; done #doesn't work :-( ``` Is there an easier/less ugly/better idiom for this sort of thing? I have also tried enclosing the commmand in parenthesis, but that doesn't work either (it only opens one plot)... ``` for PLT in *.png; do ( display ${PLT} ) ; done ``` EDIT Note that I am working in an interactive terminal. If I write a script and break the second for loop into multiple lines, it works just fine...

Original source