Shell的echo指令运用
2020-02-01 12:06
831 查看
1、echo指令,用于字符串的输出。字符串是一组由" "包围起来的字符序列,echo 将第一个"作为字符串的开端,将第二个"作为字符串的结尾。即“ ”内为echo要输出的内容。
若和其他循环联合使用时,需与done连用,例如:
for i in time do echo "$i is not well" done
输出结果为time is not well
2、read xx : xx是所要读取的内容,在脚本运行后,需手动输入
#!/bin/sh read name echo "$name is a test"
例如:运行后为下方所示
name@localhost:~$ ./test.sh
在第二行直接输入it,回车,输出
name@localhost:~$ ./test.sh it it is a test
3、转义符
echo "\"It is a test\""
可输出双引号,输出结果如下:
"It is a test"
转义字符的含义
4、-e 使转义字符生效
如直接将-e输出,则运行的解释器不对,可尝试bash 或dash
5、输出结果xxx定向至文件mylie
echo "xxx" > myfile
6、用单引号,将原样输出字符串,不进行转义或取变量
例如 echo ‘$name"’,将原样输出‘ ’内的内容,
输出结果:$name"
7、反引号 ` 则直接显示命令的运行结果
例如:date命令
echo `date`
输出结果为当前日期
Thu Jul 24 10:08:46 CST 2019
- 点赞
- 收藏
- 分享
- 文章举报
相关文章推荐
- Shell脚本echo指令使用小技巧
- shell脚本学习7——显示指令:echo和printf
- 老大让我学Linux之echo指令,awk,grep,sed指令及shell上的socket程序实例
- echo shell commands as they are executed
- shell后台执行指令At
- shell的echo命令
- shell sed指令全解
- Shell下通过echo+telnet在远端执行命令
- shell中使用echo命令输出wget获取的网页时,却输出了当前路径下的所有文件
- shell脚本echo输出不换行功能增强实例
- Linux的shell中echo改变输出显示样式
- shell下使用echo打印彩色字体及彩色背景
- V-bind指令运用加深
- shell脚本中echo显示内容带颜色的实现方法
- SHELL指令
- shell--echo/printf
- Shell echo用法
- shell十三问之3:别人echo、你也echo,是问echo知多少?
- VB创建快捷方式的简易方法--运用Wscript.Shell
- 在shell中使用echo命令输出带颜色的文本-转