LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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, 01: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 01:14 PM.
 
Old 10-17-2017, 07: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: 261

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


Reply



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

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

All times are GMT -5. The time now is 01:31 AM.

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
Open Source Consulting | Domain Registration