linux 单引号,双引号,反引号
2014-03-26 11:06
253 查看
转自:http://kmoving.blog.163.com/blog/static/205049197201242211111682/
单引号
目的: 为了保护文字不被转换.除了他本身. 就是说除去单引号外, 在单引号内的所有文字都是原样输出.
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` #反引号在此无法实现函数功能.
双引号
目的: 为了包含文字或者函数段. 除了本身,反引号内的函数,$开头的变量和\开头反转换的字符外, 其余都是直接输出.
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
反引号
目的是为了在双引号内保持函数转换. 但单引号内其无作用.
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` #在单引号内无作用.
总结
fdv=`date +%F`echo "Today $fdv"
在倒引号内的 date +%F 会被视为指令,执行的结果会带入 fdv 变数中。
单引号
目的: 为了保护文字不被转换.除了他本身. 就是说除去单引号外, 在单引号内的所有文字都是原样输出.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` #反引号在此无法实现函数功能.
双引号
目的: 为了包含文字或者函数段. 除了本身,反引号内的函数,$开头的变量和\开头反转换的字符外, 其余都是直接输出.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
反引号
目的是为了在双引号内保持函数转换. 但单引号内其无作用.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` #在单引号内无作用.
总结
单引号
被单引号用括住的内容,将被视为单一字串。在引号内的代表变数的$符号,没有作用,也就是说,他被视为一般符号处理,防止任何变量替换。双引号
被双引号用括住的内容,将被视为单一字串。它防止通配符扩展,但允许变量扩展。这点与单引数的处理方式不同。反引号
在前面的单双引号,括住的是字串,但如果该字串是一列命令列,会怎样?答案是不会执行。要处理这种情况,我们得用反单引号来做。fdv=`date +%F`echo "Today $fdv"
在倒引号内的 date +%F 会被视为指令,执行的结果会带入 fdv 变数中。
相关文章推荐
- Linux的库文件(一)
- linux学习笔记之常见操作
- CentOS6.5 Ambari1.4.4安装配置实战
- Linux Epoll介绍和程序实例
- centos中安装tahoeLAFS的一些注意点
- 每天学一点linux:系统运行级别与关机
- linux安装man中文手册
- 在Virtual Box中搭建Tiny Core Linux SSH服务器
- linux常用命令
- linux下错误的捕获:errno和strerror的使用
- [进程管理]linux 下 进程和线程的区别(baidu 面试)
- Centos 6.4 python 2.6 升级到 2.7
- Linux 使用CDT编辑器编辑C/C++语言时出现的问题和解决方案
- 手动编译安装配置实现LAMP(不完整版)
- CentOS安装中文汉字输入法ibus
- 移植iperf(mips-linux)
- linux最新分区方案
- 嵌入式Linux C笔试题积累
- Linux 系统性能评估
- linux常用命令