suppress the output to screen in shell script

萝らか妹 提交于 2019-12-06 02:56:50

问题


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 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

how is it possible?


回答1:


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

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.

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.



来源:https://stackoverflow.com/questions/5960567/suppress-the-output-to-screen-in-shell-script

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!