English 中文(简体)
b 现金获得一只指挥部的体积和显示数?
原标题:bash obtain wc -l number and display in one command?

我确信,这一点将显而易见,但目前正在这样做:

count=`find $dir -type f ( -perm -007 ) -print 2>/dev/null | wc -l`

这给我带来了希望,但 do在屏幕上显示任何东西(不过,我uck掉了任何错误线)。

是否有办法这样做(把烟 count计成变量),同时把产出显示给独角,由一位指挥? I m prettyure some such as tee 这里可以使用,但我的脑 t不象。

否则,用<代码>tee和>cat将其重新编成wc的推论撰写人,但我很相信,这样做必须有更合理的方式。

edit: Sorry, it seems the question was unclear. I don t want to show the count to screen, i want to show the output that i ve been counting, i.e: the output from find

最佳回答

Ah,因此,你想要印刷正常产出,在<代码>上有相应的数字?

为此:

count=`find $dir -type f ( -perm -007 ) -print 2>/dev/null | tee /dev/tty | wc -l`
问题回答

Ok, 对后来更新的问题的答复

粗略做法是 n,但会因非定论而失败(例如,host的当地东道方呼呼声;/dev/tty败)。

It could just be

count=`find $dir -type f ( -perm -007 ) -print 2>/dev/null | tee >(cat >&2) | wc -l`

相当于

count=`find $dir -type f ( -perm -007 ) -print 2>/dev/null | tee /proc/self/fd/2 | wc -l`

If you don t want to/cannot use stderror (fd 2) as the sidechannel here, then you can open a duplicate of the original stdout and refer to it instead:

exec 3>&1
count=`find $dir -type f ( -perm -007 ) -print 2>/dev/null | tee /proc/self/fd/3 | wc -l`

页: 1

回答你澄清的问题。 这一数额以可变的计数计算,并显示:

found=$(find $dir type f ( -perm -007 ) -print 2>/dev/null)
count=$(echo -e "$found" | wc -l)
echo -e "$found"

我不敢肯定我完全理解,因为正如书面的,确定指挥不需要上级,也不会造成任何错误。 我不知道,你是否需要产出去做,或者你只是想看看看看看看它是否发挥作用,在这种情况下,主人也会同样工作。 我将这样做:

count=`find $dir -type f -perm -007 -print -fprint /dev/stderr | wc -l`

You can print the output of find to screen, if you tee the stdout of the find command to stderr (here via an anonymous fifo).

如果您的档案名称或途径含有新的线索,那么你们的计票将令人不安。 因此,使用发现的印数特征,然后删除所有星号(not)和下限指挥,最后在最后用推测tes的tes。

# show output of find to screen
count=`find . -type f ( -perm -007 ) -print0 2>/dev/null | tee >(tr     
  > /dev/stderr) | tr -dc    |  wc -c`
echo "$count"

# show output of count to screen
count=`find . -type f ( -perm -007 ) -print0 2>/dev/null | tee >(tr -dc    | wc -c > /dev/stderr) | tr -dc    |  wc -c`
echo "$count"




相关问题
Parse players currently in lobby

I m attempting to write a bash script to parse out the following log file and give me a list of CURRENT players in the room (so ignoring players that left, but including players that may have rejoined)...

encoding of file shell script

How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks

Bash usage of vi or emacs

From a programming standpoint, when you set the bash shell to use vi or emacs via set -o vi or set -o emacs What is actually going on here? I ve been reading a book where it claims the bash shell ...

Dynamically building a command in bash

I am construcing a command in bash dynamically. This works fine: COMMAND="java myclass" ${COMMAND} Now I want to dynamically construct a command that redirectes the output: LOG=">> myfile.log ...

Perform OR on two hash outputs of sha1sum

I want perform sha1sum file1 and sha1sum file2 and perform bitwise OR operation with them using bash. Output should be printable i.e 53a23bc2e24d039 ... (160 bit) How can I do this? I know echo $(( ...

Set screen-title from shellscript

Is it possible to set the Screen Title using a shell script? I thought about something like sending the key commands ctrl+A shift-A Name enter I searched for about an hour on how to emulate ...

热门标签