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"

 

相关文章:

  • 2022-12-23
  • 2018-12-21
  • 2022-01-26
  • 2022-12-23
  • 2021-09-06
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-13
  • 2021-07-29
  • 2022-12-23
相关资源
相似解决方案