[me@linuxbox ~]$ echo this is a       test
this is a test

shell 会对echo进行单词分割(word splitting)去除多余的空白。

 [me@linuxbox ~]$ echo The total is $100.00
The total is 00.00

因为$1是一个未定义的变量,所以参数扩展会将$1替换为空字符串。

引用的目的就是由选择性的避免不想要的扩展。

一、双引号(Double Quotes)

将text放在双引号内时,所有特殊字符的特殊含义都将消失。但是字符'$','\','‘反引号’'除外,这就意味着单词分割、路径名扩展、波浪线扩展和花括号扩展都将失效,但是参数扩展、算术扩展、和命令替换仍将生效。

 [me@linuxbox ~]$ ls -l two words.txt
ls: cannot access two: No such file or directory
ls: cannot access words.txt: No such file or directory

单词分割功能会将two words.txt分割成two  和word.txt两个部分。使用双引号就可以避免这种现象出现

 [me@linuxbox ~]$ ls -l "two words.txt"
-rw-rw-r-- me me -- : two words.txt

记住:参数扩展、算术扩展、命令替换在双引号内仍然有效。

 [me@linuxbox ~]$ echo "$USER $((2+2)) $(cal)"
me February
Su Mo Tu We Th Fr Sa

二、单引号(Single Quotes)

如果我们想抑制所有扩展,那么使用单引号。

 [me@linuxbox ~]$ echo text ~/*.txt {a,b} $(echo foo) $((2+2)) $USER
text /home/me/ls-output.txt a b foo 4 me
[me@linuxbox ~]$ echo "text ~/*.txt {a,b} $(echo foo) $((2+2)) $USER"
text ~/*.txt {a,b} foo 4 me
[me@linuxbox ~]$ echo 'text ~/*.txt {a,b} $(echo foo) $((2+2)) $USER'
text ~/*.txt {a,b} $(echo foo) $((2+2)) $USER

三、转义字符(Escaping Characters)

通常使用转义字符(backslash)放在双引号中有选择性的来进行扩展。

 [me@linuxbox ~]$ echo "The balance for user $USER is: \$5.00"
The balance for user me is: $5.00

最新文章

  1. js对象克隆方法
  2. 【ZJOI2013】k大数查询 BZOJ 3110
  3. WinServer 2008 远程桌面连接设置
  4. USBD_STATUS
  5. 循序渐进Python3(十二) --1--  web框架之django
  6. mouse scrollings and zooming operations in linux & windows are opposite
  7. 6/13 sprint2 看板和燃尽图的更新
  8. iOS_SN_百度地图基本使用(1)
  9. python高级编程之选择好名称:pepe8和命名最佳实践
  10. JS 原型 & 继承
  11. google搜索指南
  12. ECMAScript 6 学习(一)generator函数
  13. Install VirtualBox Guest Additions for elementary os
  14. 【十二】jvm 性能调优工具之 jhat (JVM Heap Analysis Tool)
  15. XSplit Quality, VBV-Buffer, VBV-Maxrate and Preset Settings
  16. 游戏搭服自动化脚本shell
  17. 2018-2019 2 20165203 《网络对抗技术》Exp6 信息搜集与漏洞扫描
  18. LOJ.6284.数列分块入门8(分块)
  19. 【译】SSH隧道:本地和远程端口转发
  20. 在eclipse中的maven工程中执行maven命令的步骤

热门文章

  1. cut 从/a/b/c/d/e获取/a/b/c
  2. python:Django 简介。
  3. 2019基于python的网络爬虫系列,爬取糗事百科
  4. POJ 2135 /// 最小费用流最大流 非负花费 BellmanFord模板
  5. 自动化监控系统(二)连接数据库,创建app,添加model,同步数据库
  6. 待办消息查询sql
  7. 案例2:tab栏切换
  8. 函数中的toString
  9. nodejs mysql 连接数据库
  10. 引用opencv异常