SUMMARY: Shell scripting question

From: Atul Gore <>
Date: Wed Nov 29 2006 - 17:50:08 EST
As usual this list was/is very helpful.   The responses kept/keep coming.
Following people took time out of their busy schedules and responded ( in
descending order of response received ) :

Peter D Gray, Joe (Webpro), David Ledger, Chris Hoogndyk, Arif Mahmood,
Alan Jurgensen, Ric Anderson, Daniel Denes, Gary Paveza, John Leadeham,
Tim Wright, Mark Slater, Bernd Schemmer

Many Thanks for your responses!


1. The simple answer is to add

set -x

as the first line of each subroutine to be debugged.

2. More sophisticated solution would be to declare a environment
variable, say DEBUG and include the following line in each subroutine.

${DEBUG:+set -x}

or something like :

[ $DEBUG  = on ] && set -x

and in each function :

[ x$DEBUG = xon ] && set -x

You could customize it if you want by declaring  a separate debug
variable for each of the subroutines.

3. Another solution is as follows:

Use ksh or bash to develop shell-scripts, even if you use /bin/sh to
run them. This allows you to use PS4 (which is printed before each
line of an execution trace (where you have set -x)).

Try this at the start of your scripts:

PROGNAME=`basename $0`
PS4="trace \$PROGNAME \${FUNCNAME}() \$LINENO: "

4. Another solution is as follows :

You must add "set -x" to every function or use

typeset -ft $( typeset +f )

*after* definining all sub routines e.g.

function1() {


function2() {


# main:
typeset -ft $( typeset +f )

# add your code here

Many Thanks everyone!

________________________________________Best Regards... ... Atul


  From: "Atul Gore" <>
  Subject: Shell scripting question
  Date: Tue, 28 Nov 2006 23:18:31 -0800
  Hello Experts:

  Needed help in debugging shell scripts. How do I debug subroutines in
  shell scripts.

  If -xv is used on the first line of the script after the shell, it
  verbose debugging information, however, it does neither print
  nor verbose information if the shell script contains any subroutines

  Please help! As always, help will be appreciated!

  ________________________________________Best Regards... ... Atul


  Get FREE company branded e-mail accounts and a Web site from
  Office Live
  sunmanagers mailing list


Fixing up the home? Live Search can help
sunmanagers mailing list
Received on Wed Nov 29 17:50:54 2006

This archive was generated by hypermail 2.1.8 : Thu Mar 03 2016 - 06:44:03 EST