The linux command 之引用
[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
The linux command 之引用的更多相关文章
- 《The Linux Command Line》 读书笔记04 Linux用户以及权限相关命令
Linux用户以及权限相关命令 查看身份 id:Display user identity. 这个命令的输出会显示uid,gid和用户所属的组. uid即user ID,这是账户创建时被赋予的. gi ...
- 《The Linux Command Line》 读书笔记02 关于命令的命令
<The Linux Command Line> 读书笔记02 关于命令的命令 命令的四种类型 type type—Indicate how a command name is inter ...
- 《The Linux Command Line》 读书笔记01 基本命令介绍
<The Linux Command Line> 读书笔记01 基本命令介绍 1. What is the Shell? The Shell is a program that takes ...
- Linux Command Line Basics
Most of this note comes from the Beginning the Linux Command Line, Second Edition by Sander van Vugt ...
- Linux Command Line 解析
Linux Command Line 解析 0 处理模型 Linux kernel的启动包括很多组件的初始化和相关配置,这些配置参数一般是通过command line进行配置的.在进行后续分析之前,先 ...
- 15 Examples To Master Linux Command Line History
When you are using Linux command line frequently, using the history effectively can be a major produ ...
- 10 Interesting Linux Command Line Tricks and Tips Worth Knowing
I passionately enjoy working with commands as they offer more control over a Linux system than GUIs( ...
- Reso | The Linux Command Line 的中文版
http://book.haoduoshipin.com/tlcl/book/zh/ 本书是 The Linux Command Line 的中文版, 为大家提供了多种不同的阅读方式. 中英文双语版- ...
- [笔记]The Linux command line
Notes on The Linux Command Line (by W. E. Shotts Jr.) edited by Gopher 感觉博客园是不是搞了什么CSS在里头--在博客园显示效果挺 ...
随机推荐
- adapter设计模式
适配器设计模式 将一个类的接口转换成客户希望的另外一个接口.Adapter 模式使得原本由于接口不兼容而不能一起工作的那些类可以一起工作 例如:现在有一个220V的插口,而手机不能直接接上去,因为锂电 ...
- 2014 mathtype分块列向量输入 PPT动画制作
1.mathtype分块列向量的输入 http://zhidao.baidu.com/link?url=pV7TazWe-Ld5qgxNcJCQdRaA8ILEgmXRP211F5U0Cst0xNfU ...
- Centos 能ping通域名和公网ip但是网站不能够打开,服务器拒绝了请求。打开80端口解决。
博客搬迁,给你带来的不便,敬请谅解! http://www.suanliutudousi.com/2017/10/29/centos-%E8%83%BDping%E9%80%9A%E5%9F%9F%E ...
- java-day26
## DOM简单学习:为了满足案例要求 * 功能:控制html文档的内容 * 获取页面标签(元素)对象:Element * document.getElementByI ...
- 实现简单的PHP接口,以及使用js/jquery ajax技术调用此接口
主要介绍下如何编写简单的php接口,以及使用js/jquery的ajax技术调用此接口. Php接口文件(check.php): <?php $jsonp_supporter = $_GET[‘ ...
- Center OS 部署Tomcat服务
一.下载tomcat tomcat官网下载软件包,官网:https://tomcat.apache.org/ 点击download,进入下载页面,下载如下版本: 下载完成后用ftp上传到服务器,SSH ...
- 笔记49 在Spittr应用中整合Hibernate
在前边构建的Spittr应用中整合Hibernate 由于最近所学的hibernate都是使用xml方式进行配置的,所以在与以Java方式配置的Spittr应用结合时就会出现一些小问题,在此进行总结. ...
- photoshop钢笔工具简单记录
1. 移动锚点 Ctrl + 左键 2. 增加.删除锚点 左键(显示+.-) 3. 直线曲线相互转换 Alt + 左键(注意提示) 默认情况下为直线,按住Alt鼠标左键点击目标锚点,目标锚点两边的直线 ...
- leetcode-140-单词拆分②*
题目描述: 第一次提交:超时 O(N**N) class Solution: def wordBreak(self, s: str, wordDict: List[str]) -> List[s ...
- Delphi 日期函数列表
引用单元 :DateUtils CompareDate 比较两个日期时间值日期部分的大小CompareDateTime 比较两个日期时间值的大小CompareTime 比较两个日期时间值时间部分的大小 ...