Running a Script- and debugging.

Steven W. Orr steveo at syslang.net
Tue Sep 22 17:18:08 UTC 2009


On 09/22/09 10:52, quoth Jim:
> FC11/KDE
> 
> I have a script to run for setting up a Samsung CLX3175FN, when I start
> it it hangs. and doesn't say why , how can I find why it hangs ?
> 
> I'm running it from the terminal as root.
> 

Something I've used for years that has served me well:

export PS4='+${0##*/} line $LINENO: '

Put that in your .bash_profile (or in your .bashenv which is sucked in when
you log in, like I do).

Also, if you code for debugging, life gets easier:

errmsg()
{
    echo -e "$@" 1>&2
}

derrmsg()
{
    ((debug)) && errmsg "$@"
}

die()
{
    errmsg "$@"
    exit 1
}

You can then add calls to getops to activate debug mode.

typeset -i seen_d=0
typeset -i seen_D=0
typeset debug=0
typeset opt

usage()
{
    typeset err="$1"
    errmsg "$err"
    cat << EEIIEEIIOO 1>&2
Usage: $prog [-d] [-D] blah blah blah
EEIIEEIIOO
    exit 1
}
prog=${0##*/}
while getopts :dD opt $@
do
    case ${opt} in
    d)
        (( seen_d == 1 )) && usage 'too many -d' || seen_d=1
        debug=1
        ;;

    D)
        (( seen_D == 1 )) && usage 'too many -D' || seen_D=1
        set -x	# or whatever you need
        ;;
    h | *)
        usage 'Help text or unknown option'
        ;;
    esac
done


-- 
Time flies like the wind. Fruit flies like a banana. Stranger things have  .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 261 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/fedora-list/attachments/20090922/e417ee05/attachment-0001.sig>


More information about the fedora-list mailing list