Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Returning different values for same code?

Programming languages, Coding, Executables, Package Creation, and Scripting.
Post Reply
Message
Author
Sephiroth
Posts: 1012
Joined: 2007-07-05 03:30
Location: North Carolina, USA

Returning different values for same code?

#1 Post by Sephiroth »

Alright, I have a problem here. I am developing a script to automate some database setup, but I have an issue I cannot figure out. I prompt for some input with whiptail and select a default if nothing is entered. However, if you do not enter anything, it normally returns 0, but this time it is returning an empty value.

Code: Select all

  # This one does work!

  # Set the source path
  TMPPATH=$(whiptail --backtitle "Linux Build Configuration" \
    --title "Source-Code Path" \
    --inputbox "Default: $SRCPATH" 0 60 \
    3>&2 2>&1 1>&3)

  # Exit if cancelled
  if [ $? != "0" ]; then
    echo "Cancelled by the user. No modifications have been made to your system."
    exit 0
  fi

  # Change the path only if it was modified
  if [ ! -z "$TMPPATH" ]; then
    SRCPATH="$TMPPATH"
  fi

  # This one does NOT work?!

  # Get the database admin username
  DB_TMP=$(whiptail --backtitle "Linux Build Configuration" --title "Database Administrator Username" \
    --inputbox "Default: root" 0 60 \
    3>&2 2>&1 1>&3)

  # Exit if cancelled
  if [ $? != "0" ]; then
    echo "Cancelled by the user. No modifications have been made to your databases."
    return 0
  fi

  # Set the admin username if one was specified
  if [ ! -z "$DB_TMP" ]; then
    DB_ADMIN="$DB_TMP"
  fi
So what is wrong with the second code?
Intel C2Q 3.06GHz, 8GB PC-10600, Dual 250GB SATA 3.0GBps RAID-0, Dual GTX295 2GB, X-Fi Gamer
P4/3.20GHz HT, 2GB DDR400, 120GB SATA, 7800GS 256MB, Audigy IV w/4.1 Speakers
AMD Turion64x2 1.60GHz, 1GB DDR2(667), 120GB PATA, ATI1100M

User avatar
saulgoode
Posts: 1445
Joined: 2007-10-22 11:34
Been thanked: 4 times

Re: Returning different values for same code?

#2 Post by saulgoode »

Let's try the obvious first. Have you made an assignment to $DB_ADMIN earlier in the script?
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -- Brian Kernighan

Post Reply