[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. java实现邮件定时发送

    最近做项目时客户提出了一个需求:系统定时发送E-mail到其客户,达到通知的效果.先将实例分享给大家,如果确实有一些帮助的话,请大家来点掌声! 首先介绍java定时器(java.util.Timer) ...

  2. vue computed 源码分析

    我们来看看computed的实现.最简单的一个demo如下: <html> <head> <meta http-equiv="Content-Type" ...

  3. 【HDOJ】P1215 七夕节

    题目意思很简单,不解释 有两种方法, 1是暴力法,不就是 2就是下面要讲的方法 假如果说一个数n可以被b整除,那么一定可以被b的因子整除 那么我需要做的就是枚举这些因子 多余的请看代码 #includ ...

  4. PHP之数据连接方法(二)

    首先API接口,无非就是通过该程序去处理数据的数据,及判断数据的准确性. 因此我们需要一个DBTool的操作方法. DBTool地址:https://github.com/gfarmhuang/DBT ...

  5. Storm框架设计

  6. selenium IDE的安装及录制回放的简单使用

    1.Selenium IDE下载地址为http://docs.seleniumhq.org/download/(需要翻墙) 2.直接单机“Download version”后面的版本号即可开始下载 3 ...

  7. linux fcntl 对文件描述符控制

    linux fcntl 对文件描述符控制 linux fcntl 对文件描述符控制 linux fcntl 对文件描述符控制

  8. 2 java程序入门

    1. 第一个java  class  { public static void main(String[] args) { System.out.println("Hello World!& ...

  9. python编程学习day03

    1.文件操作 (1)打开文件 f = open ("文件名称",mode='' ",encoding="utf-8") mode=操作方式 encod ...

  10. python 相关操作

    json转字典: #如:{"Message":"OK","RequestId":"9922A379-7373-492C-842A- ...