Shell echo命令
打印字符
// 下面两行代码效果一致
echo "It is a test"
echo It is a test
打印转义字符
echo "\"It is a test\""
// 引号也可以省略
echo \"It is a test\"
打印结果:
"It is a test"
"It is a test"
打印 隐藏 换行
// 显示换行
echo -e "OK! \n" # -e 开启转义
echo "It it a test"
// 不显示换行
echo -e "OK! \c" # -e 开启转义 \c 不换行
echo "It is a test"
显示结果定向至文件
echo "It is a test" > myfile
原样显示字符 不进行转义
echo '$name\"'
// 输出结果: $name\"
录入参数
read -p "请输入一段文字:" -n 6 -t 5 -s password
echo "\npassword is $password"
- -p 输入提示文字
- -n 输入字符长度限制(达到6位,自动结束)
- -t 输入限时
- -s 隐藏输入内容