[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. jquery 临时存值

    function toSort(orderBy) { if (orderBy == $('#orderBy').data("order")) {// 再次点击同一个排序时 $('# ...

  2. [已解决]报错:ValueError: Expected 2D array, got scalar array instead

    报错代码: new_x = 84610 pre_y = model.predict(new_x) print(pre_y) 报错结果: ValueError: Expected 2D array, g ...

  3. PyUnit (unittest) 的用法

    PyUnit(unittest) 是 Python 自带的单元测试框架,用于编写和运行可重复的测试.PyUnit 是 xUnit 体系的一个成员,xUnit 是众多测试框架的总称,PyUnit 主要用 ...

  4. dp思维

    题目传输门 题意:有n个房间,m个诅咒,每个房间有一个数值,刚开始有一个初始值,每次进入一个房间可以选择消除诅咒或者不消除,消除诅咒只能顺序消除,消除诅咒就是拿初始值和房间的数值做运算,求最后最大的数 ...

  5. 【踩坑】IDEA 设置 JVM 参数

    1.可视化界面设置 Run->Edit Configuration... 然后设置 2.配置文件设置 打开 IDEA 安装目录,看到有一个 bin 目录,其中有两个 vmoptions 文件,需 ...

  6. uboot刷机

    ath> tftp xx.zpk Trying eth0 Using eth0 device TFTP from server 192.168.1.104; our IP address is ...

  7. AbstractQueuedSynchronizer 详解

    package java.util.concurrent.locks; 基本介绍 AbstractQueuedSynchronizer(队列同步器)可以看作是并发包(java.util.concurr ...

  8. luoguP1134 阶乘问题 [数论]

    题目描述 也许你早就知道阶乘的含义,N阶乘是由1到N相乘而产生,如: 12! = 1 x 2 x 3 x 4 x 5 x 6 x 7 x 8 x 9 x 10 x 11 x 12 = 479,001, ...

  9. Vue.js框架的基础指令

    Vue.js 渐进式 javascript 框架,可以独立完成前后端分离式web项目的javascript框架 js是页面脚本语言,用来控制或是辅助页面搭建,vue是js功能的集合体. 三大主流前端框 ...

  10. pure-ftpd 配置

    # Disallow anonymous connections. Only allow authenticated users. NoAnonymous yes # If you want simp ...