简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM