Shell 脚本学习笔记七:echo与printf命令

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 20:46   1889   0

echo 命令:用于字符串的输出

1、显示普通字符串

echo "It is a test";

echo It is a test;

2、显示转义字符

echo "\"It is a test\"";

3、显示变量

echo "$name It is a test";

4、显示换行

echo -e "OK! \n"; // -e:开启转义

echo "It is a test";

5、显示不换行

echo -e "OK! \c"; // -e:开启转义 \c:不换行

echo "It is a test";

6、显示结果定向至文件

echo "It is a test" > myfile

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

echo '$name\"'

8、显示命令执行结果

echo `date`

printf 命令

printf 命令的语法:

printf format-string [arguments...]

参数:

format-string:格式控制字符串

arguments:参数列表

printf 格式只指定了一个参数,但多出的参数仍然会按照该格式输出,format-string 被重用,如果没有 arguments,那么 %s 用NULL代替,%d 用 0 代替

转载于:https://www.cnblogs.com/fanxiaocong/p/7068791.html

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP