- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Shell script debugging
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
Discussions
Forums
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
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
тАО04-17-2005 12:38 AM
тАО04-17-2005 12:38 AM
Shell script debugging
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-17-2005 12:54 AM
тАО04-17-2005 12:54 AM
Re: Shell script debugging
sh -x my_script.sh
or change the first line of the script, from:
#!/bin/sh
to
#!/bin/sh -x
If you use sh/bash ofcourse.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-17-2005 12:55 AM
тАО04-17-2005 12:55 AM
Re: Shell script debugging
You can run it either as
sh -x script
or
insert set -x into the script on the place, which you want to debug
HTH
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-17-2005 12:32 PM
тАО04-17-2005 12:32 PM
Re: Shell script debugging
It will show each step of your script that was executed (with a + in front of each command) but not exactly line by line. A line that has several commands piped into each other will show each command separately. The if or test statements will be shown but the lines that were not executed won't be shown.
To help with the above scenario, use -x and -v. The -v option shows each line (including comments). Note that because the shell is interpreting the script, the original statements and the trace lines may not always be interleaved together. But it does help see where the script is located during the test run.
Another feature of set -x is that the output goes to stderr. Normally, stdout and stderr go to the screen together, but suppose you want to step through the script one page at a time:
sh -vx myscript | more
What you'll see is all the lines for listing and debugging (immediately) and any of the stdout from the script will go to: | more. To put the two together so that the more command controls all output:
sh -x -v myscript 2>&1 | more
The 2> refers to redirecting stderr and the &1 refers to file descriptor 1 which is stdout. 2>&1 effectively ties both types of output together, so now the more command sees both streams of text.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-17-2005 06:10 PM
тАО04-17-2005 06:10 PM
Re: Shell script debugging
#!/bin/ksh
#debug
hostname
# debug starts
set -x
ls
echo bye
set +x
echo over
exit 0
HTH.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-18-2005 12:47 AM
тАО04-18-2005 12:47 AM
Re: Shell script debugging
or
# sh -x script.sh
- f. halili