您的位置:首页 > 运维架构 > Shell

[转]Shell中单引号,反单引号及双引号用法

2008-12-15 22:00 267 查看
A. bash中单引号: "''"

目的: 为了保护文字不被转换.除了他本身. 就是说除去单引号外, 在单引号内的所有文字都是原样输出.

1. [root@jszwl161 SP49EP9]# echo '$*><!'

$*><!

2. [root@jszwl161 SP49EP9]# echo 'she is crying: "help"'

she is crying: "help"

3. [root@jszwl161 SP49EP9]# echo '////'

////

4. [root@jszwl161 SP49EP9]# echo 'hah 'test''

hah test #略去了所有'

5. [root@jszwl161 SP49EP9]# echo ' today is `date`'

today is `date` #反引号在此无法实现函数功能.

B. bash中的双引号 " "" "

目的: 为了包含文字或者函数段. 除了本身,反引号内的函数,$开头的变量和/开头反转换的字符外, 其余都是直接输出.

1. [root@jszwl161 SP49EP9]# echo "today is `date`"

today is Fri Jul 4 08:03:34 GMT 2008

2. [root@jszwl161 SP49EP9]# echo "today is 'date'"

today is 'date'

3. [root@jszwl161 SP49EP9]# echo "////"

//

4. [root@jszwl161 SP49EP9]# echo "test "test""

test test

C. 反引号" `` "

一般在Tab键上方,数字1键的左面,其作用是把反单引号中命令的执行结果作位参数传递给其前面的命令。

# ls -l `ls -t | tail -1`

目的是为了在双引号内保持函数转换. 但单引号内其无作用.

1. [root@jszwl161 SP49EP9]# echo "today is `date`"

today is Fri Jul 4 08:03:34 GMT 2008 #将函数date转换.

2. [root@jszwl161 SP49EP9]# echo ' today is `date` '

today is `date`#在单引号内无作用.
http://blog.myspace.cn/e/401935644.htm
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: