shell的输入和输出

1.echo    echo [option] string

           -e 解析转义字符

           -n 回车不换行,linux系统默认回车换行

            转移字符 \c \t \f \n

#!/bin/bash

#echo

echo -e "this echo's 3 newlne\n\n\n"

echo "OK"

echo

echo "this is echo's 3 ewline\n\n\n"

echo "this log file have all beendone">mylogfile.txt

[test@szbirdora ~]$ sh echod.sh

this echo's 3 newlne

 

OK

this is echo's 3 ewline\n\n\n

上面可以看到有-e则可以解析转移字符,没有不能解析。echo空输出为空

2.read 可以从键盘或文件的某一行文本中读入信息,并将其赋给一个变量

read variable1 variable2

eg.

#!/bin/bash

#readname

echo -n "first name:"

read firstname

echo -n "last name:"

read lastname

echo "this name is $firstname $lastname"

toto@toto-virtual-machine:~/c$ sh readname.sh

first name:toto

last name:toto

this name is toto toto

 

3.cat 显示文件的内容,创建内容,还可以显示控制字符

 cat [options]filename1 filename2

    -v   显示控制字符(Windows文件)

 cat命令不会分页显示,要分页可以采用more、less

4.管道|

5.tee 把输出的一个副本输送到标准输出,另一个副本拷贝到相应的文件中,一般与管道合用 tee [options] files

         -a 在文件中追加

eg.

[test@szbirdora 1]$ echo |tee myfile

[test@szbirdora 1]$ cat myfile

 

将myfile文件置空

6.文件重定向

command>filename                                      ---覆盖输出 

command>>filename                                    ---追加输出

command>filename>&1                               ---把标准输出和标准错误重定向

command<<delimiter                                   ---输入直到delimiter分解符

command<filename                                     ----输入文件内容到命令

command<-                                                   --- 关闭标准输入

>nullfile.txt                                                    ---创建字节为0的文件

command1<filename>command3              ---按从左到右顺序执行

eg.

说明:myfile为空间

[test@szbirdora 1]$ df -lh>myfile

[test@szbirdora 1]$ cat myfile

Filesystem            SizeUsed Avail Use% Mounted on

/dev/sda1             20G 3.3G   16G 18% /

none                 2.0G     0 2.0G   0% /dev/shm

/dev/sda2             79G   17G   59G 23% /u01

/dev/sda4             28G 3.9G   22G 15% /u02

[test@szbirdora 1]$ df -lh>myfile

[test@szbirdora 1]$ cat myfile

Filesystem            SizeUsed Avail Use% Mounted on

/dev/sda1             20G 3.3G   16G 18% /

none                 2.0G     0 2.0G   0% /dev/shm

/dev/sda2             79G   17G   59G 23% /u01

/dev/sda4             28G 3.9G   22G 15% /u02

[test@szbirdora 1]$ df -lh>>myfile

[test@szbirdora 1]$ cat myfile

Filesystem            SizeUsed Avail Use% Mounted on

/dev/sda1             20G 3.3G   16G 18% /

none                 2.0G     0 2.0G   0% /dev/shm

/dev/sda2             79G   17G   59G 23% /u01

/dev/sda4             28G 3.9G   22G 15% /u02

Filesystem            SizeUsed Avail Use% Mounted on

/dev/sda1             20G 3.3G   16G 18% /

none                 2.0G     0 2.0G   0% /dev/shm

/dev/sda2             79G   17G   59G 23% /u01

/dev/sda4             28G 3.9G   22G 15% /u02

[test@szbirdora 1]$ cat >>myfile<<exit

> China

> Hubei

> Suizhou

> exit

[test@szbirdora 1]$ cat myfile

China

Hubei

Suizhou

7.exec 可以用来替代当前shell。现有任何环境变量都会清除

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

涂作权的博客

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值