Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

script question 4

Status
Not open for further replies.

extremedatos

Technical User
Feb 22, 2010
54
AR
hi all,

i would like to know if there's any way i can run a script step by step?

thanks
 
Maybe put a read between each step so that processing is continued once return is pressed.

The internet - allowing those who don't know what they're talking about to have their say.
 
Hi

If you want to debug a Bash script, there is no step-by-step execution.

If you want to know which lines are executed, you can put [tt]set -o xtrace[/tt] at the beginning of your script. If you set [tt]PS4='$LINENO+ '[/tt], then the line number will be also displayed.


Feherke.
 
Nice thanks to all, one more question please,,,,
how can i execute it with out really running the script?
like in a test mode.. the problem is i have some scripts on a server and i want to run them but i don't want to make any of the changes that the script dose.

thanks!!!!!!
 
Perhaps replace all actions with an echo to indicate which action would be taking place if run properly?

The internet - allowing those who don't know what they're talking about to have their say.
 
Bash has an option to read and parse each line in a script, but not actually run it. This is for checking syntax.

From "[tt]man bash[/tt]"...
Code:
set [--abefhkmnptuvxBCHP] [-o option] [arg ...]
    <<<edited>>>
    Options, if specified, have  the  following  meanings:
    -n   Read commands but do not execute them.  This may be used
         to check a shell script  for  syntax  errors.   This  is
         ignored by interactive shells.
So a "[tt]set -n[/tt]" early in the script should do. Or, make your first line of your script like this...
Code:
#!/bin/bash -n
Also turning on "[tt]-x[/tt]" and "[tt]-v[/tt]" can add a lot of debug information.

 
Nice one Sam, I wasn't aware of that but it looks useful.

The internet - allowing those who don't know what they're talking about to have their say.
 
It's also a wonderful practical joke. Just adding a small and hardly noticeable "-n" to the she-bang line of someone's script can make them almost go insane.

[bigsmile]



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top