0
TMPFILE=/tmp/jboss_ps.$$
     ${PS} ${PS_OPTS} | \
     grep ${JBOSS_HOME}/java | \
     egrep -v " grep | \
     tee | $0 " | ${AWK} '{print $NF " "}' | \
     sort -u > ${TMPFILE} 2>/dev/null

I want to know what this precise line is doing from the code above

egrep -v " grep | \
     tee | $0 "

At first i thought that that line is searching for everything that does not contain this exact string "grep | \ tee | $0" but it appears that egrep is processing the pipes, so what's the significance of the pipes here, does it mean OR ? From my test it appears that it's not, but if it means output redirection then what's the inner grep getting ? And why is tee alone too ?

user2548720
  • 109
  • 2
  • 2
  • 7
  • Look up bash `tee` -- it lets you split the output so that you can redirect it to a file (as with '>') but still see it on the screen or still use it with other pipes (the `|`) symbols. – beroe Oct 30 '13 at 01:39
  • Is there a backslash at the end of the first line? The quoted string `" grep | tee | $0 "` is split across two lines with a backslash; that's a bad idea (and I had to experiment to figure out just what it does). – Keith Thompson Oct 31 '13 at 15:55

2 Answers2

0

AFAIK

egrep -v " grep | \
     tee | $0 "

is nothing but

egrep -v " grep | tee | $0 "

where \ is the continuation character in bash.

egrep is same as grep -E

-v for inverted selection

tee just another string

so egrep -v " grep | tee | $0 " does find lines that have the string {java path} and within this results, all the lines that doesn't match the condition {either of grep OR tee OR $0 } where $0 is the filename not a '$0' because it uses DOUBLE QUOTES and not single quotes :)

" commands | $variables " has the tendency to expand the variables and use the utility.

Srini V
  • 11,045
  • 14
  • 66
  • 89
  • 1
    `tee` is not just another string. It is a pipe splitter. – beroe Oct 30 '13 at 01:37
  • `tee` is part of a quoted string (which happens to be split across two lines). I suspect the code in the question is incorrect; it's at least formatted poorly. – Keith Thompson Oct 31 '13 at 15:51
0

The commands in the pipeline before the egrep command is probably something like ps -ef|grep .... The egrep -v (Option)line you asked about is simply omitting lines you don't want in the results, in this case the initial grep command issued by the script, any tee commands and lastly $0 which is the name of the this script being executed. egrep allows to enter multiple patterns enclosed in double quotes and separated by pipe symbol. Syntax egrep -[option or not] "patern1|patern2|patern..."

Yvonne B
  • 21
  • 1