- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Stepping thru shell scripts
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2001 12:51 PM
12-27-2001 12:51 PM
I have some shell scripts that I have written. I always end up running the scripts to see if it works the way I want it to.
Is there a way to step through each line in the script to see what it is doing? And also see the value of the variables etc etc... I guess debug the script?
Thank you,
Sanjay
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2001 12:54 PM
12-27-2001 12:54 PM
Re: Stepping thru shell scripts
sh -x your_script
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2001 12:55 PM
12-27-2001 12:55 PM
Re: Stepping thru shell scripts
ksh -x [script file name]
where it will display each line as it is run; you can also add the following to the scripts to get line numbers to display:
PS4='${0##*/}:$LINENO: '
typeset -ft $(typeset +f)
HTH
--
mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2001 12:56 PM
12-27-2001 12:56 PM
Re: Stepping thru shell scripts
If it is csh script then
#csh -x script_name
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2001 12:57 PM
12-27-2001 12:57 PM
Re: Stepping thru shell scripts
sh -x "script name" would the fast and best way to check.
-USA..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2001 01:04 PM
12-27-2001 01:04 PM
Re: Stepping thru shell scripts
HH,
C
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2001 01:11 PM
12-27-2001 01:11 PM
SolutionThe only way I know to do this is to use a read command (example: read trash) in the middle of the loop. This stops the process and waits for an
When you're through with debugging, just do a global search and delete on the 'read trash' commmand.
Good luck with your debugging.
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2001 05:20 PM
12-27-2001 05:20 PM
Re: Stepping thru shell scripts
In addition to what has been highlighted above, if you want to see the states of all environmental shell variables (exported ones) and script variables during your script debugging, you can insert set command statements in your script. Simply insert "set" after the line you want to debug.
Hope this helps. Regards.
Steven Sim Kok Leong
Brainbench MVP for Unix Admin
http://www.brainbench.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2001 06:15 AM
12-28-2001 06:15 AM
Re: Stepping thru shell scripts
Use the -x option in the 1st line of the script where you usually specify the shell you are writing in:
ex. /usr/bin/ksh -x
/usr/bin/sh -x
/usr/bin/csh -x
/usr/bin/bash -x
etc.....
Steven is right about the "set" command, use it preceeding any of your variables to see how they are utilized in the script.
Good luck
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2001 06:16 AM
12-28-2001 06:16 AM
Re: Stepping thru shell scripts
Use after the variable line in the script, not preceeding it. Sorry about the mistake (no flogging at this time).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2001 07:48 AM
12-28-2001 07:48 AM
Re: Stepping thru shell scripts
Thank you for all your replies. I have tried the -x option and it works very good. The set command also works great. I know the set command displays all the variables, is there a way to only display only the local variables that I use in the script?
Thank again,
Sanjay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2001 09:34 AM
12-28-2001 09:34 AM
Re: Stepping thru shell scripts
If you want to display local variables, I believe that if you define the set command within a function area of the script you will then display the local variables:
Example using ksh.
function asystem {
print in function $0: $1 $2
var1="in function"
}
var1="outside of function"
print var1: $var1
print $0: $1 $2
asystem systemarg1 systemarg2
print var1: $var1
print $0: $1 $2
Once you invoke this script the function asystem changes the value of the variable var1 from "out of function" to "in function", that change is known outside the function while $0, $1, & $2 will have different functions within the script.
Hope this helps.