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

Shell编程基础:单引号和双引号含义区别

2009-06-03 17:02 477 查看
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. 反引号" `` "

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

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` #在单引号内无作用.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: