Why does ksh allow unpaired quotes while bash does

2019-04-06 19:17发布

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 }`

标签: bash shell awk ksh
1条回答
爷、活的狠高调
2楼-- · 2019-04-06 19:52

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.

查看更多
登录 后发表回答