Shell script debugging


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script debugging
# 1  
Old 05-27-2013
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-
Code:
[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

Last edited by vbe; 05-27-2013 at 10:18 AM.. Reason: Please use code tags dor your code and data, thanks
# 2  
Old 05-27-2013
First of all I don't understand this syntax:
Code:
[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!
# 3  
Old 05-27-2013
may i know which shell are you using as $GREP seems more like a shell variable then grep(in smaller case) command.
# 4  
Old 05-27-2013
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`
# 5  
Old 05-27-2013
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.
# 6  
Old 05-28-2013
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 ! Smilie
hope ya'll understand

~cheers
# 7  
Old 05-28-2013
We understand that the command:
Code:
cat abc.txt | grep 123

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

does exactly the same thing much more efficiently.

You're saying that the command:
Code:
[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:
Code:
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.
This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Debugging mode while executing Unix Shell Scripting

Hi, Is there any debugging tool for Unix Shell Script like we have gdb in C/C++? Also please let me know how to close the thread is it automatic or we have to close it manually. Thanks and Regards (1 Reply)
Discussion started by: diehard
1 Replies

2. Shell Programming and Scripting

Debugging a script with noexec

Newbie question. I cannot get "set -n" or "set -noexec on" to work on Linux or AIX! According to the man page and what I read online, it should inform me of syntax errors without executing commands in your script. So, can someone PLEASE explain why this does not work? ... (2 Replies)
Discussion started by: fgoyti
2 Replies

3. Shell Programming and Scripting

Debugging a beginner shell script...

I have been following a tutorial on bash which has proven to be very helpful. However, i am stuck with a command not found issue when asking for a y/n response from the user. Below is the part of code I believe is giving me grief... I have been trying to work through this for 3 hours now.... Please... (5 Replies)
Discussion started by: brokepunk
5 Replies

4. Shell Programming and Scripting

Debugging shell scripts

Any there any utilities or ways of debugging shell scripts? I know something like: sh -x <script> (1 Reply)
Discussion started by: proactiveaditya
1 Replies

5. Shell Programming and Scripting

debugging the shell script with out actually running

Hello, Some one asked me in the inteview.... The question is, How do we debug the schell script before even running..... Interviewer told me one clue... There is SET command to accomplish this... Can any one tell me what kind of set commands.... Thanks. (2 Replies)
Discussion started by: govindts
2 Replies

6. Shell Programming and Scripting

script debugging

is there any way you can add a breakpoint in a script so you can stop on it? i have used -xv in my shebang but the script just runs and i want it to stop at a specific point in the script. appreciate any help. (1 Reply)
Discussion started by: npatwardhan
1 Replies

7. UNIX for Advanced & Expert Users

which one method is best for debugging the shell script?

Hi All, How to debug the unix shell script? which one is the best way to do the debuging ? suggession would be appreciate Regards, Siva P Bangalore (2 Replies)
Discussion started by: psiva_arul
2 Replies

8. Shell Programming and Scripting

debugging a script??

Hi all, Am working on a script to understand the flow control of it.. Since i am from a C background i looking out for an easy way to analyze the script as it runs .. In C/C++ we have F7 that starts execution from main() and proceeds accordingly.. I was wondering if there is a same approach... (2 Replies)
Discussion started by: wrapster
2 Replies

9. Shell Programming and Scripting

FTP script debugging

Hello all, I am trying to run a script and have not had much success running it...ne help debugging it will be appreciated..The ftp script alone works but not within the while loop. below is the script #!/usr/bin/ksh destination_server=servename destination_user_id=un... (1 Reply)
Discussion started by: alfredo123
1 Replies

10. Shell Programming and Scripting

HP-UX Debugging Shell script

Hi, I was using AIX - ksh shell , and inorder to debug shell script I used set -vx to echo all the commands which are being executed. Can anybody tell me the corresponding method in HP-UX - in tcsh shell. Regards Shihab (1 Reply)
Discussion started by: shihabvk
1 Replies
Login or Register to Ask a Question