shell变量的替换,命令的替换,转义字符

1,shell变量的替换

变量可以根据变量是否为空或者被删除,而被替换为特定的值

${var}  变量本来的值

$(var:-word)   如果变量为空,或者已被删除那么返回word,但是不改变var的值

name="xiaoming"

echo "xiaoming 's age is ${age:-12}"

ech   "age = ${age}"

>>>>>>>>

xiaoming 's age is 12

age =

>>>>>>>

$(var:=word)   如果变量为空,或者已被删除那么返回word,改变var的值

name="xiaoming"

age=11

echo "xiaoming 's age is ${age:+12}"

ech   "age = ${age}"

>>>>>>>>

xiaoming 's age is 12

age = 12

>>>>>>

$(var:?word)   如果变量为空,或者已被删除那么返回word,那么将message送到标准错误输出

name="xiaoming"

echo "xiaoming 's age is ${age:-12}"

ech   "age = ${age}"

>>>>>>>>

./hello.sh: 行 8: age: 12

>>>>>>>

$(var:+word)   如果var被定义,那么返回word,但是不改变var的值

举例

name="xiaoming"

age=11

echo "xiaoming 's age is ${age:=12}"

ech   "age = ${age}"

>>>>>>>>

xiaoming 's age is 12

age = 11

>>>>>>>

2,命令替换是指shell可以先执行命令保存,然后在适当的地方输出

lll=`ls`  注意这里是反引号,不是单引号
echo ${lll}

3,转义字符

\\    反斜杠

\a   警报 响铃

\b   退格(删除键)

\f   换页

\n   换行

\r   回车

\t   水平制表符

\w   垂直制表符

上一篇:学习笔记50—多重假设检验与Bonferroni校正、FDR校正


下一篇:FDR错误发现率-P值校正学习[转载]