How to show error line number while using sh somefile.sh

Discussion in 'Programming/Scripts' started by andipurwito, Oct 31, 2007.

  1. andipurwito

    andipurwito New Member

    Hi all...
    I have a file: somefile.sh
    It contains some command below:

    #!/bin/sh
    mynet="192.168.128.0/24"
    iptables -A INPUT -p TCP -s 0/0 -d $mynet -j Accept


    then i run it using this command:
    #sh somefile.sh

    How to show line number in that file when an error happen?
    What is the option?

    regards
    Andi
     
  2. falko

    falko Super Moderator Howtoforge Staff

    Not sure how to do this, but you could do something different: if you suspect a specific command to throw errors, just put the following in the next line in the script:

    Code:
    if [ $? != 0 ]; then
        echo "ERROR"
    fi
    If the script displays "ERROR", then you know that the previous command threw an error; otherwise it must have been a different command, and you can move the above lines to another location in the script to continue testing.
     

Share This Page