#!/bin/bash
#演示全引用和部分引用
#双引号和没引号的区别
variable1=2010
echo "$variable 1"
echo $variable 1
variable2= "x y z" # #字符之间用多个空格隔开
echo "$variable 2" # #双引号
echo $variable 2 # #没引号
#单引号和双引号的区别
echo "$PWD is the current directory." # #双引号
Echo ' $PWD is the current direcotry. ' # #单引号
#单引号的问题和解决方法
echo "Why can ' t I write ' s between single quotes" # #单引号出现的问题
Echo ' Why can ' ' "'" ' t I write ' "'" ' s between single quotes ' # #解决单引号的问题
# #命令替换
#反引号的用法
Echo ' World ' # #调用world命令
Echo ' Who ' # #调用who命令
#字符串分割问题与解决办法
Echo ' Echo ' # #表示将结果以字段显示
echo "' Echo '" # #表示将结果以字符串显示
Echo ' echo x y ' # #表示结果是x y two strings
echo "' Echo x y '" # #表示结果是x y as a string
dirlist= ' ls-l * ' # #命令替换
Echo $dirlist # #不引用dirlist变量, line break is deleted
echo "$dirlist" # #引用dirlist变量, line break retention
#$ () 's Embedding method
firstlinelength=$ (expr Length "$ (sed-n ' 1p ' *)")
Echo $firstlinelength
#转义
echo \ # #输出转义符
echo ' echo \ \ ' # #输出空本行
echo $ (echo \ \) # #输出单斜线符
#转义符的运用
echo "\ $PWD" # #转义 $ symbol
echo "This was \" The 60th National day\ "# #转义双引号"
echo "\ \" # #转义符号本身
Variable=\ # #将转义符赋值给变量
#将一串符号赋值非变量
Variable= "() \\{}\$" "
Echo $variable
echo "$variable"
Ifs= ' \ '
Echo $variable
echo "$variable"
This article is from the "All Night" blog, please make sure to keep this source http://endmoon.blog.51cto.com/8921900/1616630
Reference usage description for shell scripts