燮preSS输出到stdout管道时回音 [英] Suppress output to StdOut when piping echo

查看:140
本文介绍了燮preSS输出到stdout管道时回音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过目录检索与某种类型的所有文件输出到一个文本文件中的bash脚本。我有一个工作,它只是也写了一堆的输出来安慰我不想(该文件的名称)

I'm making a bash script that crawls through a directory and outputs all files of a certain type into a text file. I've got that working, it just also writes out a bunch of output to console I don't want (the names of the files)

下面是有关的code,到目前为止,TMPFILE是我写的文件:

Here's the relevant code so far, tmpFile is the file I'm writing to:

for DIR in `find . -type d` # Find problem directories
do
        for FILE in `ls "$DIR"` # Loop through problems in directory
        do
                if [[ `echo ${FILE} | grep -e prob[0-9]*_` ]]; then
                        `echo ${FILE} >> ${tmpFile}`
                fi
        done
done

我把到文本文件中的文件是由正则表达式的概率描述的格式[0-9] * _(类似prob12345_01)

The files I'm putting into the text file are in the format described by the regex prob[0-9]*_ (something like prob12345_01)

我在哪里管从回声$ {}文件的grep到的输出,它仍然输出到stdout,这是我想避免的。我认为这是一个简单的修复,但它逃避我。

Where I pipe the output from echo ${FILE} into grep, it still outputs to stdout, something I want to avoid. I think it's a simple fix, but it's escaping me.

推荐答案

这一切都可以在一个单一find命令来完成。试想一下:

All this can be done in one single find command. Consider this:

find . -type f -name "prob[0-9]*_*" -exec echo {} >> ${tmpFile} \;

编辑:

更简单:(感谢 @GlennJackman

find . -type f -name "prob[0-9]*_*" >> $tmpFile

这篇关于燮preSS输出到stdout管道时回音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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