Shell echo命令
来源:互联网 发布:淘宝网店从哪里注册 编辑:程序博客网 时间:2024/05/17 07:52
Shell echo命令
Shell 的 echo 指令与 PHP的 echo指令类似,都是用于字符串的输出。命令格式:
echo string
您可以使用echo实现更复杂的输出格式控制。
1.显示普通字符串:
echo "It is a test"
这里的双引号完全可以省略,以下命令与上面实例效果一致:
echo Itis a test
2.显示转义字符
echo "\"It is a test\""
结果将是:
"Itis a test"
同样,双引号也可以省略
3.显示变量
read 命令从标准输入中读取一行,并把输入行的每个字段的值指定给 shell变量
#!/bin/sh
read name
echo "$name It is a test"
以上代码保存为 test.sh,name接收标准输入的变量,结果将是:
[root@www~]# sh test.sh
OK #标准输入
OK Itis a test #输出
4.显示换行
echo -e"OK!\n"# -e 开启转义
echo "It it a test"
输出结果:
OK!
It it a test
5.显示不换行
#!/bin/sh
echo -e"OK!\c"# -e 开启转义 \c不换行
echo "It is a test"
输出结果:
OK!Itis a test
6.显示结果定向至文件
echo "It is a test"> myfile
7.原样输出字符串,不进行转义或取变量(用单引号)
echo '$name\"'
输出结果:
$name\"
8.显示命令执行结果
echo `date`
注意: 这里使用的是反引号 `,而不是单引号 '。
结果将显示当前日期
ThuJul24 10:08:46 CST2014
- shell: 命令echo、cat
- shell之echo命令
- 十三、Shell echo命令
- shell echo命令介绍
- Shell echo命令
- Shell echo命令
- Shell echo命令
- Shell echo命令
- Shell echo命令
- shell echo 命令
- Shell echo命令
- Shell echo命令
- Shell echo命令
- Shell echo命令
- shell echo命令
- Shell echo命令
- Shell echo命令
- Shell echo命令
- angularjs学习笔记(二)控制器1
- javascription基础知识【学习整理中】
- Android设计模式
- malloc\colloc
- 1002. 写出这个数 (20)
- Shell echo命令
- shadowsocks后端一键脚本
- python__爬虫自学异常 (二)
- 读取MP3内嵌信息
- 10065---【Java多线程】线程池的工作原理详解(上)
- K-近邻算法
- POJ 2422 The Wolves and the Sheep 笔记
- IntelliJ IDEA安装、配置、测试(win7_64bit)
- 机器学习--神经网络算法系列--交叉熵(Cross_entropy)