LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 06-05-2006, 06:48 AM   #1
konstantinmiller
LQ Newbie
 
Registered: Apr 2006
Distribution: Slackware
Posts: 7

Rep: Reputation: 0
Debugging shell scripts


Hi!

Is there any possibility to automatically stop bash script execution after each command and continue after for example a key press?

Thanks for advices!

Konstantin
 
Old 06-05-2006, 07:02 AM   #2
Hobbletoe
Member
 
Registered: Sep 2004
Location: Dayton, Oh
Distribution: Linux Mint 10, Linux Mint 11
Posts: 148

Rep: Reputation: 17
Just put a read statement in after each statement. If you want any key press to work, do a

Code:
read -n 1
That way, it will automatically return after the first character typed.
 
Old 06-05-2006, 07:26 AM   #3
konstantinmiller
LQ Newbie
 
Registered: Apr 2006
Distribution: Slackware
Posts: 7

Original Poster
Rep: Reputation: 0
:-) That's not what I mean by automatically! I would not like to modify the script! And with read I wouldn't be able to stop after commands embedded in ``!
 
Old 06-05-2006, 08:01 AM   #4
Hobbletoe
Member
 
Registered: Sep 2004
Location: Dayton, Oh
Distribution: Linux Mint 10, Linux Mint 11
Posts: 148

Rep: Reputation: 17
I can not say that I know of a way to do that. You might want to look into the --debugger option for bash to see if there is anything there that will help you to debug a script.
 
Old 06-07-2006, 02:41 AM   #5
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,434

Rep: Reputation: 303Reputation: 303Reputation: 303Reputation: 303
You could write a small function with all the code and exit option.

Then by calling it later, even back-ticked it could exit or continue.
 
Old 06-07-2006, 12:03 PM   #6
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Etch/Lenny/Squeeze
Posts: 3,485

Rep: Reputation: 308Reputation: 308Reputation: 308Reputation: 308
No, bash doesn't offer that capabilities. It stated explicitely in the advanced bash scripting guide. However, if you call:
Code:
sh -x myscript.sh
from the command line you'll get a trace on your screen with all steps the program has taken.

jlinkels
 
Old 06-07-2006, 12:28 PM   #7
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,858
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

I don't think there's any "Visual Studio-like" IDE for debugging, if that's what you mean.

Usually a few debug "echo" statements (the shell equivalent of "printf") is all you need.

"bash/sh/ksh -x myscript" is a good technique.

Equivalently, you can also add a "set -x" at the part of the script where you want to start tracing, and a corresponding "set +x" where you want to stop tracing.

Here's a good overview (one of many, similarly good tutorials):
http://mercury.chem.pitt.edu/~sasha/...ticle216.shtml

'Hope that helps .. PSM
 
Old 06-07-2006, 12:39 PM   #8
johnMG
Member
 
Registered: Jul 2003
Location: CT, USA
Distribution: Debian Sarge (server), Etch (work/home)
Posts: 601

Rep: Reputation: 30
Instead of running the code as a script, just type it in line by line at your shell prompt.

Bam. Interactive debugging.
 
Old 06-07-2006, 02:15 PM   #9
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,434

Rep: Reputation: 303Reputation: 303Reputation: 303Reputation: 303
Perhaps have a look at the program execline which executes code by lines. feed each command to execline and include a read.
 
Old 06-08-2006, 05:33 AM   #10
nx5000
Senior Member
 
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 51
In bash,
you can put :
Code:
set -x
at the beginning of your script

Same for this line, it will redirect all stdout (echo,..) to a file
Code:
script 1> /tmp/myshell.log
This one will redirect all output to /dev/null and then your script will be "mute"
Code:
script 1> /dev/null
The advantage is you don't need to modify your entire script.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference between kernel - debugging and application debugging topworld Linux - Software 2 03-30-2006 12:50 AM
Debugging a Bash Shell Script solarblast Linux - General 1 02-23-2006 01:44 AM
Shell Scripts baruah Linux - Certification 1 02-02-2006 01:19 PM
Visual Debugging and Linux Kernel Debugging Igor007 Programming 0 09-30-2005 10:33 AM
shell scripts rocketgo Linux - General 10 12-01-2003 05:20 AM


All times are GMT -5. The time now is 04:41 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration