1

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?

Roun
  • 1,449
  • 1
  • 18
  • 25
  • See: [Difference between single and double quotes in bash](http://stackoverflow.com/q/6697753/3776858) – Cyrus Apr 23 '16 at 20:09

1 Answers1

3

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.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621