LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-17-2017, 02:11 PM   #1
JoseKreif
Member
 
Registered: Jul 2015
Location: Iowa
Distribution: CentOS 6.6, RHEL Server release 5.5 (Tikanga)
Posts: 58

Rep: Reputation: 0
Bash is not exiting the while loop.


Maybe I'm having a bad day, or maybe this is another reason for why I hate writing bash.

Code:
#!/bin/bash

xvloop='x'
xchoice=''
XSTATUS="N/A"

while [ "$xvloop" = 'x' ]; do
     clear

        printf  "\n\n
Some Status: ${XSTATUS}

                Some Sub Menu

                A: Some Function
                B: Go Back

        Choice: "

        read choice

        case $xchoice in
          [Aa]) echo "Hello World"; XSTATUS="Changed"; clear;;
          [Bb]) xvloop='Z'; xchoice=""; clear; break;;
     esac

# DEBUG MESSAGE
echo "${xvloop} - ${xchoice}"

done

# DEBUG MESSAGE
echo "PAST DONE"
I am stuck in the while loop. When I print out the xvloop variable, it's still set to x... While xchoice is "" (blank).

EDIT: D'OH! I am reading a null variable.

Last edited by JoseKreif; 10-17-2017 at 02:14 PM.
 
Old 10-17-2017, 08:45 PM   #2
ShadowCat8
Member
 
Registered: Nov 2004
Location: San Bernardino, CA
Distribution: Gentoo, Arch, (RedHat4.x-9.x, FedoraCore 1.x-4.x, Debian Potato-Sarge, LFS 6.0, etc.)
Posts: 258

Rep: Reputation: 52
Greetings,

Well, I would say that the issue with this code has nothing to do with which scripting language you used... You would likely still have an issue for the small error (probably typo) that is there whether it was written in BASH, csh, ksh or python... So, you were probably just having a bad day.

On line 20, I would recommend changing "read choice" to "read xchoice" so you are actually taking the input to the variable you are checking against in the case switch.

HTH your day get better. Let us know.

Last edited by ShadowCat8; 10-17-2017 at 08:46 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
problem exiting loop doughyi8u Programming 5 08-19-2014 11:46 PM
[SOLVED] Bash: Exit loop without exiting script keif Programming 7 11-06-2013 05:48 PM
[SOLVED] [BASH] non-empty variable before loop end, is empty after exiting loop aitor Programming 2 08-26-2010 10:57 AM
Exiting BASH function without exiting sourced environment SwingingSimian Programming 10 08-12-2009 01:59 AM
infinite loop not exiting when killed kinkle Linux - General 1 04-11-2009 08:55 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:27 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration