6、shell的echo命令

shell的echo命令

echo是shell的一种指令,用于字符串的输出,格式如下:

echo string

1、显示普通字符串

echo "It is a string"

2、显示转义字符

echo "\"It is a string\""

3、显示变量

name = good
echo "It is a $name "

4、显示换行

cho -e "OK! \n" # -e 开启转义
echo "It is a test"

输出:

OK!

It is a test

5、显示不换行

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

输出:

OK! It is a test

6、显示结果定向至文件

echo "It is a test" > myfile

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

echo '$name\"'

输出:

$name\""

8、显示命令执行结果

echo `date`

注意: 这里使用的是反引号 `, 而不是单引号 '

结果将显示当前日期

Thu Jul 24 10:08:46 CST 2014
posted @ 2023-01-09 18:02  站着说话不腰疼  阅读(167)  评论(0)    收藏  举报