Search code examples
bashparallel-processinggnu-parallel

Why does sem (GNU parallel) behave differently with single quotes and double quotes?


I can't understand the following behavior of sem from GNU Parallel. When I use single quotes, it seems to work well:

sem -j1 'echo $(date);sleep 5;echo $(date)'
sem --wait    

gives

Sat Apr 23 15:46:50 EDT 2016
Sat Apr 23 15:46:55 EDT 2016

However, when I use double quotes.

sem -j1 "echo $(date);sleep 5;echo $(date)"
sem --wait

the result is

Sat Apr 23 15:46:08 EDT 2016
Sat Apr 23 15:46:08 EDT 2016

where it seems that the sleep 5 is totally ignored.

Could anyone explain why this happens? Is it caused by GNU parallel or bash?


Solution

  • It has nothing to do with sem or GNU parallel, but everything to do with the shell.

    When you use double-quotes for strings, the shell expands all environment variable references at once. If you use single-quoted strings the shell doesn't do that variable expansion.