1

First time today i got to know about $DBG_SH # dormant debugging directive (Apr. 92 column) someone used in the shell script. I search around the globe but did not get the exact answer, how and why it is used.

Here is the link.

Its Just Being Used at the top of the script as, which i tested now and looks as it gives every bits of Information you are doing at the base code level , here i'm adding and deleting the entries via ldapmodify command and it gives all information what it is does at the background without debugger.

#!/bin/sh
$DBG_SH
flags="-v"
case $1 in
"live") # Live server
  LDAPSERVER=ldapprod
  ADMIN="uid=bason,ou=people,o=real.com"
  pass=""
  ;;
"dev") # test system
  LDAPSERVER=ldapdev
  ADMIN="uid=bason,ou=people,o=real.com"
  pass=""
 ;;
*)
  echo "Usage: $0 live|dev [ldif filename] [cont]"
  echo "       live|dev      - specify live or dev server"
  echo "       ldif filename - specify filename containing ldif"
  echo "       cont          - continue on error"
  exit 1 ;;
esac

if [ ! -f "$2" ];then
  /bin/echo -n "Path to LDIF file: "
  read PATH_TO_LDIF
else
  PATH_TO_LDIF="$2"
fi
if [ "$3" = "cont" ];then
  flags="$flags -c"
fi
if [ `uname -s` = "Linux" ];then
  flags="$flags -x"
fi
if [ -z "$pass" ]; then
  /bin/echo -n "Password: "
  read -s pass
  echo
fi

ldapmodify $flags -h $LDAPSERVER -D "$ADMIN" -w $pass -f $PATH_TO_LDIF
exit $?
2
  • 1
    It mostly isn't used — I've not seen it in use. It allows you to use DBG_SH='echo Hello' mainscript and the script will echo 'Hello' at the point where $DBG_SH appears. You can substitute more useful commands there, in theory. Commented Jun 11, 2018 at 4:46
  • @JonathanLeffler, thnx for your inputs .. i have Just tested it and it gives nice code level information which a command doing via shell script. Commented Jun 11, 2018 at 4:59

2 Answers 2

2

I guess it is not used much. However, if you run your script in some environment having DBG_SH set to some set command you could have some debugging output.

Think of something like env DBG_SH='set -xv' yourscript.sh

Sign up to request clarification or add additional context in comments.

1 Comment

Basile, thnx for your input , i have Just tested it and it gives nice code level information which a command doing via shell script. i have updated the post as well.
2

I'd steer clear of it. If you wanted to find documentation for it, I think you'd have to spelunk through the old Bourne shell code.

Typically, /bin/sh is hard linked to /bin/bash, and bash has checks to verify that it's invoked as sh to run in POSIX mode. bash has newer facilities for debugging, especially check man bash for trap and set.

So I'd avoid this one because:

  1. you're rarely writing scripts for old versions of Bourne
  2. if the feature is "dormant" it's deprecated, and
  3. your actual shell is usually bash and will not support obscure / deprecated features in Bourne.

That said, it might be worth it to poke around the old Bourne code to see how old Unix utilities were written back then, just as a learning experience.

1 Comment

thnx for your input , i have Just tested it and it gives nice code level information which a command doing via shell script.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.