shell的学习与巩固第四次课程echo命令 转义以及命令执行结果

转义概念对于新手来说需要特别注意!最后一个data命令 `data`   `符号为ESC下的那个键

##简单介绍一下echo命令

#1.显示普通字符串
echo "It is a test"
#如果是普通字符串 双引号可以省略

##需要注意
#2.显示转义字符
echo "\"It is a test\""
#其中“”需要转移   许多sql中也会出现这样的情况
##原样输出字符串,不进行转义或取变量(用单引号)
echo '$name\"'
#输出结果
$name\"


#3.显示变量
read name  ##read命令从标准输出中读取一行  把输入行的每个字段的值指定给shell变量
echo "$name It is a test"
#讲以上代码保存为test.sh   
sh test.sh
OK   #这里需要输入  为标准输入
#输出则为 
OK It is a test


#显示换行
echo -e "OK! \n" 
# -e 开启转义
echo "It it a test"
#输出结果
OK!
It it a test

#显示不换行
echo -e "OK! \c" 
# -e 开启转义 \c 不换行
echo "It is a test"
#输出结果
OK! It is a test

##显示结果定向至文件
echo "It is a test" > myfile

#显示命令执行结果
echo `date`
##这里使用的是反引号 `, 而不是单引号 '。
#结果将显示当前日期

你可能感兴趣的:(shell脚本入门学习)