下面的所有环境都在在REDHAT LINUX9下试验的 在LINUX中,要使转义符生效,需加参数-e 从echo的变量开始说起 如:e c h o命令输出转义符以及变量。 # echo -e "/007your home is $HOME , you are connected on `tty`"
your home is /root , you are connected on /dev/pts/1 # echo -e "/ayour home is $HOME , you are connected on `tty`" your home is /root , you are connected on /dev/pts/1 # 本例中
在e c h o命令输出之后附加换行,可以使用/ n选项:/007或/a你可以让终端铃响一声 显示出$ H O M E目录, 并且可以让系统执行t t y命令(注意,该命令用键盘左上角的符号,法语中的抑音符引起来,不是单引号 )。 $ cat echod
编辑一个新echod,如上内容,然后运行输出如下:#!/bin/sh echo -e "this echo's 3 new lines/n/n/n" echo "OK" $ ./echod
在e c h o语句中使用跳格符,记住别忘了加反斜杠/:this echo's 3 new lines OK $ $ echo -e "here is a tab/there are two tabs/t/tok"
把一个字符串输出到文件中,使用重定向符号>。here is a tab here are two tabs ok $ 在下面的例子中一个字符串被重定向到一个名为m y f i l e的文件中: $ echo "The log files have all been done"> myfile
或者可以追加到一个文件的末尾,这意味着不覆盖原有的内容:$ echo "$LOGNAME carried them out at `date`">>myfile
现在让我们看一下m y f i l e文件中的内容:The log files have all been done
引号是一个特殊字符,所以必须要使用反斜杠/来使s h e l l忽略它的特殊含义。sam carried them out at 六 11月 13 12:54:32 CST 2004 假设你希望使用e c h o命令输出这样的字符串:“/ d e v / r m t 0”,那么我们只要在引号前面加上反斜杠/即可: $ echo "/"/dev/rmt0"/"
"/dev/rmt0" $ |
shell基础五:输入和输出(echo,read,cat,管道,tee,重定向等)
最新推荐文章于 2024-03-23 00:15:00 发布
请填写红包祝福语或标题
红包个数最小为10个
红包金额最低5元