grep与管道的问题

sh/bash/dash/ksh/zsh等Shell脚本
回复
bleastrind
帖子: 32
注册时间: 2007-08-26 7:23

grep与管道的问题

#1

帖子 bleastrind » 2008-05-03 12:51

bleastrind@bleastrind-desktop:~$ sudo linux1x -addsa
ERROR! Command line arguments conflict!
Usage 1(to authenticate):
linux1x [authentication options]
authentication options are:
[-u <UserName[/password]>].specify user name and password for authentication.
[-n <NetworkDeviceName>]...specify network card name for authentication, such as eth0,eth1,etc.
[-d] ......................start authentication with daemon mode(background mode).
[-p] ......................start authentication with interactive mode, prompt user to input all the necessary information.

Usage 2(to view network status info):
linux1x -v [LastingTime]..."LastingTime" specifies the lasting time in seconds for this viewing operation(0 or without argument means forever). Also, this command will show the version of this software.

Usage 3(to configure network connection information):
linux1x -c

Usage 4(to stop network connection):
linux1x -k

___________________________________________________________________________________
bleastrind@bleastrind-desktop:~$ sudo linux1x -addsa|grep 'linux1x'
linux1x [authentication options]
linux1x -v [LastingTime]..."LastingTime" specifies the lasting time in seconds for this viewing operation(0 or without argument means forever). Also, this command will show the version of this software.
linux1x -c
linux1x -k
bleastrind@bleastrind-desktop:~$ sudo linux1x -addsa|grep 'linux1x'
linux1x [authentication options]
linux1x -v [LastingTime]..."LastingTime" specifies the lasting time in seconds for this viewing operation(0 or without argument means forever). Also, this command will show the version of this software.
linux1x -c
linux1x -k
___________________________________________________________________________________
bleastrind@bleastrind-desktop:~$ sudo linux1x -addsa|grep 'E'

bleastrind@bleastrind-desktop:~$ sudo linux1x -addsa|grep 'l'

bleastrind@bleastrind-desktop:~$
___________________________________________________________________________________
为什么返回不了第一行?
但是我sudo linux1x -addsa>1
再grep 'E' 1
就行
aBiNg
帖子: 1331
注册时间: 2006-07-09 12:22
来自: 南京

#2

帖子 aBiNg » 2008-05-03 17:49

error不是标准输出。楼主可以去翻翻有关文件描述符的文章。 :)
头像
laborer
帖子: 1016
注册时间: 2005-10-25 11:15
联系:

#3

帖子 laborer » 2008-05-03 23:03

error不是标准输出。
但这不能解释为什么
但是我sudo linux1x -addsa>1
再grep 'E' 1
就行
也许楼主最后弄错了,试试下面的命令是什么效果

代码: 全选

sudo linux1x -addsa 2>&1 | grep 'E'
hreiser@oakland:~$ killall -9 wife
police@oakland:~$ sudo find / -user hreiser
court@oakland:~$ sudo mv /home/hreiser /jail/
court@oakland:~$ sudo usermod -d /jail/hreiser -s "/usr/sbin/chroot /jail/" hreiser
bleastrind
帖子: 32
注册时间: 2007-08-26 7:23

#4

帖子 bleastrind » 2008-05-04 17:37

bleastrind@bleastrind-desktop:~$ sudo linux1x -addsa 2>&1 |grep 'E'

bleastrind@bleastrind-desktop:~$
还是什么都没有
bleastrind
帖子: 32
注册时间: 2007-08-26 7:23

#5

帖子 bleastrind » 2008-05-04 17:39

sudo linux1x -addsa 2>1
的话1里面就没有任何内容
说明不是那个原因
aBiNg
帖子: 1331
注册时间: 2006-07-09 12:22
来自: 南京

#6

帖子 aBiNg » 2008-05-04 20:21

哦,我大意了,这也许与文件描述符关系不大。
楼主命令的输出中的"ERROR.."行,据上面的结果来看,并不是错误输出。所以使用文件描述符2也没有用。

再,楼主用 commmand > 1,则是将输出导入到名为"1"的文件里,所以grep时有结果。

但楼主的这几种情况对照看,应该是矛盾的。

单看这两行:

代码: 全选

bleastrind@bleastrind-desktop:~$ sudo linux1x -addsa|grep 'linux1x' 
bleastrind@bleastrind-desktop:~$ sudo linux1x -addsa|grep 'l' 
前一个有输出,后一个没有,这个不太可能。除非同一个命令相同参数,前后两次结果不同,请楼主确认一下。
bleastrind
帖子: 32
注册时间: 2007-08-26 7:23

就是那样的..

#7

帖子 bleastrind » 2008-05-05 20:57

我也不知道为啥,这是最大的令人迷惑的地方
bleastrind
帖子: 32
注册时间: 2007-08-26 7:23

我知道怎么回事了

#8

帖子 bleastrind » 2008-06-05 14:54

是因为时间差。。
怎么才能等写完文件再执行下一步呢?
回复