shell编程 shell编程基础 单引号和双引号的区别
人气:0想了解shell编程基础 单引号和双引号的区别的相关内容吗,在本文为您仔细讲解shell编程的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:shell,编程基础,单引号,双引号,下面大家一起来学习吧。
下面用一个简单的shell程序要说明一下。 debian:~/learn/shell# cat phonebook
Alice Chebba 973-555-2015
Barbara Swingle 201-555-9257
Liz Stachiw 212-555-2298
Susan Goldberg 201-555-7776
Susan Topple 212-555-4932
Tony Iannino 973-555-1295
Stromboli Pizza 973-555-9478
debian:~/learn/shell#
debian:~/learn/shell# cat lu
# Look someone up in the phone book
grep "$1" phonebook
debian:~/learn/shell#
这是正确的lu程序,下面是运行结果。
debian:~/learn/shell# ./lu 'Susan T'
Susan Topple 212-555-4932
debian:~/learn/shell# ./lu Tony
Tony Iannino 973-555-1295
debian:~/learn/shell#
如果lu写成①grep $1 phonebook或者②grep '$1' phonebook,就会出现下面的错误结果(为什么?)。
①的结果:
debian:~/learn/shell# ./lu Tony //这种情况结果正确
Tony Iannino 973-555-1295
debian:~/learn/shell# ./lu 'Susan T' //这种情况结果错误
grep: T: No such file or directory
phonebook:Susan Goldberg 201-555-7776
phonebook:Susan Topple 212-555-4932
debian:~/learn/shell#
②的结果:
debian:~/learn/shell# ./lu Tony //这种情况结果错误
debian:~/learn/shell# ./lu 'Susan T' //这种情况结果也错误
debian:~/learn/shell#
加载全部内容