下面用一个简单的shell程序要说明一下。
debian:~/learn/shell#catphonebook
AliceChebba973-555-2015
BarbaraSwingle201-555-9257
LizStachiw212-555-2298
SusanGoldberg201-555-7776
SusanTopple212-555-4932
TonyIannino973-555-1295
StromboliPizza973-555-9478
debian:~/learn/shell#
debian:~/learn/shell#catlu
#Looksomeoneupinthephonebook
grep"$1"phonebook
debian:~/learn/shell#
这是正确的lu程序,下面是运行结果。
debian:~/learn/shell#./lu'SusanT'
SusanTopple212-555-4932
debian:~/learn/shell#./luTony
TonyIannino973-555-1295
debian:~/learn/shell#
如果lu写成①grep$1phonebook或者②grep'$1'phonebook,就会出现下面的错误结果(为什么?)。
①的结果:
debian:~/learn/shell#./luTony//这种情况结果正确
TonyIannino973-555-1295
debian:~/learn/shell#./lu'SusanT'//这种情况结果错误
grep:T:Nosuchfileordirectory
phonebook:SusanGoldberg201-555-7776
phonebook:SusanTopple212-555-4932
debian:~/learn/shell#
②的结果:
debian:~/learn/shell#./luTony//这种情况结果错误
debian:~/learn/shell#./lu'SusanT'//这种情况结果也错误
debian:~/learn/shell#
【shell编程基础 单引号和双引号的区别】相关文章:
★ 谈谈linux中flock、lockf和fcntl的区别
★ linux shell 管道命令(pipe)使用及与shell重定向区别