[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 之引用的更多相关文章

  1. 《The Linux Command Line》 读书笔记04 Linux用户以及权限相关命令

    Linux用户以及权限相关命令 查看身份 id:Display user identity. 这个命令的输出会显示uid,gid和用户所属的组. uid即user ID,这是账户创建时被赋予的. gi ...

  2. 《The Linux Command Line》 读书笔记02 关于命令的命令

    <The Linux Command Line> 读书笔记02 关于命令的命令 命令的四种类型 type type—Indicate how a command name is inter ...

  3. 《The Linux Command Line》 读书笔记01 基本命令介绍

    <The Linux Command Line> 读书笔记01 基本命令介绍 1. What is the Shell? The Shell is a program that takes ...

  4. Linux Command Line Basics

    Most of this note comes from the Beginning the Linux Command Line, Second Edition by Sander van Vugt ...

  5. Linux Command Line 解析

    Linux Command Line 解析 0 处理模型 Linux kernel的启动包括很多组件的初始化和相关配置,这些配置参数一般是通过command line进行配置的.在进行后续分析之前,先 ...

  6. 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 ...

  7. 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( ...

  8. Reso | The Linux Command Line 的中文版

    http://book.haoduoshipin.com/tlcl/book/zh/ 本书是 The Linux Command Line 的中文版, 为大家提供了多种不同的阅读方式. 中英文双语版- ...

  9. [笔记]The Linux command line

    Notes on The Linux Command Line (by W. E. Shotts Jr.) edited by Gopher 感觉博客园是不是搞了什么CSS在里头--在博客园显示效果挺 ...

随机推荐

  1. hibernate 中createQuery与createSQLQuery两者区别

    hibernate 中createQuery与createSQLQuery两者区别是:前者用的hql语句进行查询,后者可以用sql语句查询前者以hibernate生成的Bean为对象装入list返回, ...

  2. centos7.2下快速安装zabbix4.0

    本笔记是基于CentOS 7.2下最小化安装的操作系统搭建的Zabbix4.0环境,主要用于做一些企业路由器和交换机等设备的运行状态监控. 1.安装epel源 yum -y install epel- ...

  3. 运维生涯中总有一次痛彻心扉的rm命令

    为了防止误操作,配置rm命令别名,同时可以进行恢复删除文件 1. 在/tmp目录下新建两个目录,命名为:.trash,tools cd /tmp/ mkdir .trash mkdir tools 2 ...

  4. 连接分析算法-HITS-算法

    转自http://blog.csdn.net/Androidlushangderen/article/details/43311943 参考资料:http://blog.csdn.net/hguisu ...

  5. vue-cli 利用moment.js转化时间格式为YYYY年MM月DD日,或者是YYYY-MM-DD HH:MM:SS 等格式

    1.在mian.js引入moment import moment from 'moment' Vue.prototype.$moment = 'moment' 2. 在main.js 设置全局过滤器 ...

  6. JavaScript中的面向对象编程,详解原型对象及prototype,constructor,proto,内含面向对象编程详细案例(烟花案例)

    面向对象编程:   面向:以什么为主,基于什么模式 对象:由键值对组成,可以用来描述事物,存储数据的一种数据格式 编程:使用代码解决需求   面向过程编程:         按照我们分析好的步骤,按步 ...

  7. Es6中let与const的区别:(神奇的块级作用域)

    所谓的块级作用域:形成一个暂时性的死区:{    } 一.共同点: a:都是用来声明变量: b:都能形成一个块级作用域: c:都只能在声明变量的块级作用域里面有效: 二.不同点: 1.let: a:在 ...

  8. 前端 JavaScript 基础

    内容目录: 一.JavaScript介绍 二.基础语法   2.1 变量   2.2 数据类型   2.3 流程控制   2.5 函数的全局变量和局部变量   2.6 作用域   2.7 词法分析   ...

  9. 1 新增硬盘挂载home文件夹。 2 修理扇区

    一 挂载新硬盘 主机磁盘容量不够大时,想新增一颗新磁盘的时候.并将磁盘全部分割成单一分割槽,且将该分割槽挂载到/home目录,你该怎么做呢? 1  安装硬盘. 2  磁盘分区. 3 格式化磁盘 4 将 ...

  10. asp.net MVC项目,localhost响应时间过长

    1.早上高高兴兴的吃完早餐,敲了几句代码,准备调试,竟然发现VS调试项目打开的很慢,最后报错如下图 2.那就很可能是IIS问题嘛,IIS重启了一下,还是不行,在地址栏输入localhost,如下图(本 ...