Why does ksh allow unpaired quotes while bash does not?

夙愿已清 提交于 2019-12-09 16:06:29

问题


When I execute following command, on bash shell I get error but on Korn shell it runs perfectly fine. The only difference is missing single quote at the end of awk, after }. Could you help me understand why?

echo `echo "a b c d" | awk '{ print $1 }`

回答1:


In the Korn shell, both back ticks and quotes can be left unmatched, the tokenizer will try and guess where either will end and match them accordingly.

Examples:

/home/ufierro # echo "`echo ah" 
+ echo ah
+ echo ah
ah

/home/ufierro # echo `echo 'hello world` 
+ echo 'hello world'
+ echo hello world
hello world

Notice how both examples show a different case for the behavior mentioned above. The first example shows how, a single back tick within double quotes was completed during parsing and the second example shows how a single quote inside back ticks was completed as well.



来源:https://stackoverflow.com/questions/44944457/why-does-ksh-allow-unpaired-quotes-while-bash-does-not

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!