在shell脚本中将输出抑制到屏幕 [英] suppress the output to screen in shell script

查看:993
本文介绍了在shell脚本中将输出抑制到屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 我写了一个小脚本:

Hi i have written a small script:

#!/usr/bin/ksh

for i in *.DAT
do
awk 'BEGIN{OFS=FS=","}$3~/^353/{$3="353861958962"}{print}' $i >> $i_changed
awk '$3~/^353/' $i_changed >> $i_353
rm -rf $i_changed
done

exit

我对其进行了测试,并对其进行了很好的测试. 但这是将输出提供给屏幕,我不需要将输出提供给屏幕. 我只需要制成$i_353

i tested it and its wrking fine. But it is giving the output to screen i dont need the output to screen. i simply need the final file that is made $i_353

怎么可能?

推荐答案

用大括号括住脚本正文,然后重定向到/dev/null:

Wrap the body of the script in braces and redirect to /dev/null:

#!/usr/bin/ksh

{
for i in *.DAT
do
    awk 'BEGIN{OFS=FS=","}$3~/^353/{$3="353861958962"}{print}' $i >> $i_changed
    awk '$3~/^353/' $i_changed >> $i_353
    rm -rf $i_changed
done
} >/dev/null 2>&1

这也将错误发送到位桶.那可能不是一个好主意.如果您不想这样做,请删除2>&1重定向.

This sends errors to the bit-bucket too. That may not be such a good idea; if you don't want that, remove the 2>&1 redirection.

也:当心-您可能需要使用${i}_changed${i}_353.这就是为什么输出不会发送到文件的原因...您的变量${i_changed}${i_353}未初始化,因此重定向未命名文件.

Also: beware - you probably need to use ${i}_changed and ${i}_353. This is why the output is not going to the files...your variables ${i_changed} and ${i_353} are not initialized, and hence the redirections don't name a file.

这篇关于在shell脚本中将输出抑制到屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆