echo和printf都能输出内容两者之间的用法如下:
echo命令
命令格式:echo string
例如 echo “test123”
echo输出""
需要添加 \ 做转义
例如 echo “\“test123\””
echo输出到文件
echo “test123” >> 文件名 会抓加到文件末尾
echo “test123” > 文件名 会清空文件内容,只显示 test123
echo ’ ’
该方式可以禁止转义,直接输出想要的字符串
echo ‘$value"“’ 会输出 $value",其实就是原模原样的输出 单引号里面的内容
echo -e 开启转义
echo -e “abc \n” # -e 开启转义
echo “def”
输出结果:
abc
def
\n生效 换了一行
printf命令
printf format-string [arguments…]
参数说明:
format-string: 为格式控制字符串
arguments: 为参数列表。
例如:
printf “test123”
printf %s “test123”
%s %c %d %f 都是格式替代符,%s 输出一个字符串,%d 整型输出,%c