makefile中指令(tee/echo/>)

本文介绍了Linux中tee命令的功能及其参数,包括追加到文件和忽略中断信号等。接着讨论了echo命令的不同用法,@echo可以避免显示命令本身。最后,解释了文件重定向符号>和>>的区别,前者清空文件内容,后者在文件末尾追加内容。

一、tee命令

      功能是从标准输入读取,再写入标准输出和文件。

      用法:tee [OPTION]... [FILE]...

-a, --append                        追加到文件

-i, --ignore-interrupts           忽略中断信号

-p                                         诊断写入非管道的错误

--output-error[=MODE]        设置输出错误的方式,MODE 的选项在下边

--help                                   帮助文档

--version                              版本信息

MODE:

warn                   写入遇到错误时诊断

warn-nopipe       写入非管道遇到错误时诊断

exit                     写入遇到错误时退出

exit-nopipe         写入非管道遇到错误时退出

如果没有指定 --output-error,tee 会在写入管道发生错误时立即退出,写入非管道时诊断。

使用示例:

默认功能和追加功能:

[root@server dir]# echo 'This is a sentence.' | tee output
This is a sentence.
 
[root@server dir]# cat output
This is a sentence.
 
[root@server dir]# echo 'This is another sentence.' | tee -a output
This is another sentence.
 
[root@server dir]# cat output
This is a sentence.
This is another sentence.
 
[root@server dir]# echo 'This is a unique sentence.' | tee output
This is a unique sentence.
 
[root@server dir]# cat output
This is a unique sentence.

同时写入两个文件:

[root@server dir]# tee a b
they have the same content
they have the same content
^C
[root@server dir]# cat a
they have the same content
[root@server dir]# cat b
they have the same content

二、echo   &&  @echo

echo: 会在shell中显示echo这条命令和后面要输出的内容·

@echo: 不会显示echo这条命令,只会显示后面要输出的内容

例如:

echo “hello” 输出为:echo “hello” hello

@echo “hello” 输出为:hello

make在执行命令之前会把要执行的命令进行输出,称之为回显

如果要执行的命令以字符@开始,则不会回显,

1.@echo XXX…

在执行命令时,将输出XXX…

2.echo XXX…

在执行命令时,将输出echo XXX… XXX…

三、>和>>的区别

1. 执行echo时,如果用 > 输出到文件,会将文件内容清空并输出

2. 执行echo时,如果用 >> 输出到文件,会将内容从文件最后面另起一行输出

评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值