Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 10-17-2017, 01:11 PM   #1
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.



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

        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;;

echo "${xvloop} - ${xchoice}"


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 01:14 PM.
Old 10-17-2017, 07:45 PM   #2
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: 261

Rep: Reputation: 52

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 07:46 PM.


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 10:46 PM
[SOLVED] Bash: Exit loop without exiting script keif Programming 7 11-06-2013 04:48 PM
[SOLVED] [BASH] non-empty variable before loop end, is empty after exiting loop aitor Programming 2 08-26-2010 09:57 AM
Exiting BASH function without exiting sourced environment SwingingSimian Programming 10 08-12-2009 12:59 AM
infinite loop not exiting when killed kinkle Linux - General 1 04-11-2009 07:55 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:19 PM.

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