Thursday, March 29, 2012

To Debug A Shell Script

    we can use        -v  OR -x

-v

      The -v option is used to print shell commands as they are read along with the outcome of the              
       script. So if after some command if see desired output is not coming you can
       note down that commands.

    example for  sh -v sample.sh

                    echo "Warning! You are installing the Fall Creek portal software"

                    echo -n "Enter the product installation directory: "

                    read InstallDir

   OUT PUT :

                    echo "Warning! You are installing the Fall Creek portal software"

                   Warning! You are installing the Fall Creek portal software

                   echo -n "Enter the product installation directory: "

                   Enter the product installation directory: read InstallDir

-x

           The -x option is used for expanding each command. It displays the command, system variable and  

           then its expanded arguments.

  EXAMPLE FOR sh -vx sample.sh

                     echo "Warning! You are installing the Fall Creek portal software"

                    + echo 'Warning! You are installing the Fall Creek portal software'

                  Warning! You are installing the Fall Creek portal software

                  echo -n "Enter the product installation directory: "

                  + echo -n 'Enter the product installation directory: '

                 Enter the product installation directory: read InstallDir

                 + read InstallDir

No comments: