继续记录命令学习:
8. 输入输出命令:
i> echo,个别选项:不想换行,使用选项-n,因为echo会默认在输出结尾添加换行,如下:
[root@localhost ~]# echo "this is a test."
this is a test.
[root@localhost ~]#
而在使用-n后效果:
[root@localhost ~]# echo -n "this is a test."
this is a test.[root@localhost ~]#
ii> echo 使输出字符中的转义字符生效,使用-e选项:
[root@localhost ~]# echo "this is \na \ttest."
this is \na \ttest.
[root@localhost ~]#
使用-e选项后:
[root@localhost ~]# echo -e "this is \na \ttest."
this is
a test.
[root@localhost ~]#
iii> read命令,read可以从键盘或文件的某一行文本中读入信息,并将其赋予一个变量,如果指定了一个变量,那么read会将所有的输入赋予这个变量直至遇到第一个文件结束符或者回车。
注:read的一般形式为:read var1 var2 ... ,read会将读取的输入按照空格分隔,依此赋予变量var1,var2...,如果输入按照空格分割后的截断数目多余变量数,则最后一个变量将获得剩余所有输入的赋值,直至文件结束符或者回车。
iv> tee命令,tee命令会将一个副本输出到标准输出,另外一个副本重定向到指定文件。它的一般形式为:tee [ - a] filename;其中-a为追加到filename文本后。
举例: who | tee -a who.log