为什么ksh允许不成对的引号而bash不允许呢? [英] Why does ksh allow unpaired quotes while bash does not?

查看:74
本文介绍了为什么ksh允许不成对的引号而bash不允许呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我执行以下命令时,在bash shell上出现错误,但在Korn shell上运行得很好.唯一的不同是在aw之后,在}之后缺少单引号.你能帮我理解为什么吗?

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

推荐答案

在Korn shell中,后勾和引号都可以不匹配,令牌生成器将尝试猜测它们的结尾处并进行相应的匹配.

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.

示例:

/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.

这篇关于为什么ksh允许不成对的引号而bash不允许呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆