Shell脚本学习-echo命令

跟着RUNOOB网站的教程学习的笔记

shell的echo指令与PHP的echo指令类似,都是用于字符串的输出。命令格式:

echo string

1 显示普通字符串

echo "It is a test"

这里的双引号完全可以省略,后面的例子也是这样(双引号可以省略)

echo It is a test

2 显示转义字符

echo "\"It is a test\""

3 显示变量

read命令从标准输入中读取一行,并把输入行的每个字段的值都指定给shell变量

#!/bin/bash
read name
echo "$name It is a test"

4 显示换行

echo -e "OK! \n" 
echo It is a test

5 显示不换行

#!/bin/sh
echo -e "OK \c"
echo "It is s test"

6 显示结果定向到文件

echo "It is a test" > myfile

7 原样输出字符串,不进行转义或者取变量(用单引号)

扫描二维码关注公众号,回复: 2747217 查看本文章
echo '$name\"'

8 显示命令执行结果

echo `date`

这里使用的是反引号,执行的命令是显示当前日期

猜你喜欢

转载自www.cnblogs.com/hanweiblog/p/9471553.html