Shell script debugging

hi all

only the weirdest thing happened with me just now. I was debugging a shell script and I found that a step that was supposed to execute later was getting executed prior to another step for no reason. You know any ?

i mean have a look at the following command-

[if $DISPLAY xstatus | $GREP "$right...$right" ]

here it tries to grep first(and hence gives an ambiguous output) and later displays the xstatus.(It should do the opposite,right?)

also any idea what the command which frsh does ? it gives no output on my system. But it sure does something.

Your valuable inputs are always welcome

~cheers

First of all I don't understand this syntax:

[if $DISPLAY xstatus | $GREP "$right...$right" ]

Can you explain what you are trying to do? I think this statement is wrong and I really doubt if it works!

may i know which shell are you using as $GREP seems more like a shell variable then grep(in smaller case) command.

Hi,thank you for taking out your time and replying to this post.

Yoda :: just take this example "cat abc.txt | grep 123"
The only purpose was to let you kno that grep is being executed first,not the cat command.

kg_gaurav : $GREP in my script is `which grep`

Yes, the "DISPLAY" command should execute and pipe it's output to grep. It would help if you could post the whole script, or at least the portions that include the assignment to the DISPLAY variable. It might also help to post the output.

Not knowing exactly what command has been assigned to DISPLAY, I can only guess, and my first thought is that the command's normal output is to standard error and not standard out. This situation could exhibit the behaviour you describe as grep might appear to execute first (failing because of an immediate end of file on standard input?) and the standard error from the command still appearing on the tty device.

Again, that is only a guess, and posting more of the script will certainly help people answer your question.

hi all

again please consider something like this "cat abc.txt | grep 123"
All I wanna know is if there's any way that script greps first and cats later ?
We can take my script later on because its a little confidential. I cannot disclose it. Not even a snippet. But thats the crux of it ! :slight_smile:
hope ya'll understand

~cheers

We understand that the command:

cat abc.txt | grep 123

prints any line in the file abc.txt that contains the string "123". We understand that the command:

grep 123 abc.txt

does exactly the same thing much more efficiently.

You're saying that the command:

[if $DISPLAY xstatus | $GREP "$right...$right" ]

is running whatever $GREP expands to before it runs the command [if . This will probably give a syntax error because you most likely do not have a utility named [if . Since you won't tell us what error was displayed, you haven't told us what system you're using, you haven't told us what shell you're using, and you won't even use CODE tags; you're asking us to work with our hands tied behind our backs. I can guess that you would probably have better luck with:

if [ $DISPLAY xstatus | $GREP "$right...$right" ]

but there is no way that we can guess whether or not that might do what you want done with the information you have provided.

1 Like

thanks .. will work something out !!

STUPID STUPID LOGS !!