简体   繁体   English

为什么sem(GNU 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. 我无法理解来自GNU Parallel的sem的以下行为。 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. 似乎sleep 5完全被忽略了。

Could anyone explain why this happens? 谁能解释为什么会这样? Is it caused by GNU parallel or bash? 它是由GNU parallel还是bash引起的?

It has nothing to do with sem or GNU parallel, but everything to do with the shell. 它与sem或GNU并行无关,但与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. 如果使用单引号字符串,则shell不会执行该变量扩展。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么 sed a 和 sed s 命令在单引号和双引号下的转义字符表现不同? - Why do sed a and sed s commands behave differently with respect to escape characters under single quotes and double quotes? 为什么单引号和双引号在“bash -c”中的工作方式不同? - why single quotes and double quotes works differently in “bash -c”? 为什么运行带有双引号的awk会中断,但可以使用单引号? - Why Does Running Awk With Double Quotes Break But Works With Single Quotes? 为什么bash将双引号转换为单引号? - Why bash converting double quotes to single quotes? 单引号内的单引号-Bash命令行GNU parallel - Single quotes within single quotes issue - Bash command line GNU parallel 双引号,单引号和无引号的假设 - Assumption with double quotes, single quotes & no quotes 为什么bash在命令的转义双引号中添加单引号 - why is bash adding single quotes to escaped double quotes for command 为什么Shell脚本中的引号与Shell命令中的引号行为不同? - Why do quotes in shell scripts behave differently from quotes in shell commands? bash如何解析双引号和单引号 - How does bash parse double quotes and single quotes 为什么bash使用单引号和双引号? - Why is bash using single and double quotes literally?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM