Shell学习四:echo和print输出

Shell echo命令

1,显示普通字符串

echo "It is a test"
echo 'It is a test'
#双引号完全可以省略,以下命令与上面实例效果一致

echo It is a test

2,显示变量

#!/bin/sh

#read 命令从标准输入中读取一行,并把输入行的每个字段的值指定给 shell 变量
read name 
echo "$name It is a test"
echo "${name} It is a test"

3,开启转义符

#!/bin/sh

#开启换行
echo
-e "OK! \n" # -e 开启转义 echo "It is a test" :<<EOF 结果 OK! It is a test EOF

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

:<<!
结果
OK! It is a test
!

4,重定向至文件

echo "It is a test" > myfile

 

Shell printf命令

printf 命令模仿 C 程序库(library)里的 printf() 程序。

1,简单使用

printf "Hello, Shell\n"

 

posted on 2020-07-13 16:30  Huab  阅读(1918)  评论(0编辑  收藏  举报