[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. cut 从/a/b/c/d/e获取/a/b/c

    https://www.cnblogs.com/chenxiaomeng/p/10066821.html two_dir=`echo /a/b/c/d/e/f | cut -d"/" ...

  2. 当引入的类库存在一个类型时,提示“xxx”和“xxx”之间的不明确引用时,消除歧义的方法

    //using _2_命名空间和程序集.WidgetA; //using _2_命名空间和程序集.WidgetB; using System; using System.Collections.Gen ...

  3. 读书笔记---《Docker 技术入门与实践》---其一

    一.镜像1.1.搜索 搜索所有nginx镜像 $ docker search nginx NAME DESCRIPTION STARS OFFICIAL AUTOMATED nginx Officia ...

  4. mysql 8+ 忘记root密码 解决方案

    在安装完数据库后,由于自己不小心直接关闭了安装窗口,或者长时间没有使用root用户登录系统,导致忘记了root密码,这时就需要重置MySQL的root密码.当然,最简单方式自然是删除数据库的data目 ...

  5. Linux grep 后通过 | 在次grep

    grep 'info' info.log|grep 'info2' 先筛选出 包含‘info’的信息,再次筛选出包含'info2'的信息

  6. Perl 条件语句

    Perl 条件语句 Perl 条件语句是通过一条或多条语句的执行结果(True或者False)来决定执行的代码块. 可以通过下图来简单了解条件语句的执行过程: 注意,数字 0, 字符串 '0' . & ...

  7. Java中获取前一天和后一天时间

    今天在开发项目的时候遇到一个问题就是怎么获取当前时间的前一天和后一天,这个实现的逻辑并不复杂,自己要写的话的也不是难事,但是貌似感觉没必要自己写这样的方法,想想Java中的Calendar类应该有这样 ...

  8. 同构图+思维构造——牛客多校第六场E

    考的其实是同构图的性质: 1.同构图的顶点数,边数相等 2.同构图通过点的映射后邻接矩阵相同 这篇博客讲的很好https://www.jianshu.com/p/c33b5d1b4cd9 本题还需要一 ...

  9. lua之table|模块|包

    一.table table是   Lua的一种数据结构用来帮助我们创建不同的数据类型,如:数字.字典等. Lua table使用关联型数组,你可以用任意类型的值来作数组的索引,但这个值不能是   ni ...

  10. Unity中的值传递与引用传递

    1. 值类型 值类型变量本身保存了该类型的全部数据,当声明一个值类型的变量时,该变量会被分配到栈(Stack)上. 2. 引用类型 引用类型变量本身保存的是位于堆(Heap)上的该类型的实例的内存地址 ...