Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

detach process in bash for loop

Tags:

bash

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...

like image 865
mgilson Avatar asked Jun 23 '26 08:06

mgilson


1 Answers

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.

like image 157
Burton Samograd Avatar answered Jun 25 '26 02:06

Burton Samograd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!