Shell echo命令

显示普通字符串:

1
echo "It is a test"

显示转义字符

1
echo "\"It is a test\""

结果将是:

1
"It is a test"

显示变量

1
2
name="Tom"
echo "Hello $name"

显示换行

1
2
echo -e "OK! \n" # -e 开启转义
echo "It it a test"

输出结果:

1
2
3
OK!
It it a test

显示不换行

1
2
echo -e "OK! \c" # -e 开启转义 \c 不换行
echo "It is a test"

输出结果:

1
OK! It is a test

显示结果定向至文件

1
echo "It is a test" > myfile

原样输出字符串,不进行转义或取变量(用单引号)

1
echo '$name\"'

输出结果:

1
$name\"

显示命令执行结果

1
echo `date`