1: Appending(Piping and redirecting output )(--->>15071)

In an earlier mission, we looked at how to redirect output from a command to a file using >. Here's an example:

 

echo "This is all a dream..." > dream.txt

If the file dream.txt already exists, the above code will overwrite the file with the string This is all a dream.... If the file dream.txtdoesn't exist, it will be created, and the stringThis is all a dream... will be used as the content. This involves redirecting from thestandard output of the command to the standard input of the file.

If we don't want to overwrite dream.txt, and we instead want to add to it, we can use >>.

 

echo "Wake up!" >> dream.txt

The above code will append This is all a dream... to the file dream.txt. The file will still be created if it didn't exist.

Instructions

  • Overwrite the file beer.txt with the string 99 bottles of beer on the wall....
  • Append the string Take one down, pass it around, 98 bottles of beer on the wall... to the file beer.txt

 

~$ echo '99 bottles of beer on the wall...' > beer.txt ~$ echo 'Take one down, pass it around, 98 bottles of beer on the wall...' >> beer.txt

转载于:https://my.oschina.net/3198370356/blog/747149

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值