Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8566075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:34:25+00:00 2026-06-11T17:34:25+00:00

I am not looking for a different way to accomplish the apparent intention. I’m

  • 0

I am not looking for a different way to accomplish the apparent intention. I’m looking to understand why this exact syntax is not working.

[root@lvs ~]# while true;do
> echo "Would you like the script to check the second box ([y]n)?"
> read ans
>         if [ "$ans" == "n" ];then
>                 echo
>                 echo "bye"
>                 exit
>         elif [ "$ans" != "" -o "$ans" != "y" ];then
>                 echo "Invalid entry..."
>         else
>                 break
>         fi
> done
Would you like the script to check the second box ([y]n)? **"Should have continued"**

Invalid entry...
Would you like the script to check the second box ([y]n)? **"Should have continued"**
y
Invalid entry...
Would you like the script to check the second box ([y]n)? **"Correct behavior"**
alskjfasldasdjf
Invalid entry...
Would you like the script to check the second box ([y]n)? **"Correct behavior"**
n

bye

Here’s a reference that’s identical to so many others i found. I understand what it’s doing, it’s using the non logical’s for AND and OR when everything I’ve read said that it should be using logical bools.

http://www.groupsrv.com/linux/about140851.html

Ok so here it is, with Nahuel’s suggestion behaving how I had originally expected it to:

[root@lvs ~]# while true;do
> echo "Would you like the script to check the second box ([y]n)?"
> read ans
>         if [ "$ans" = "n" ];then
>                 echo
>                 echo "bye!"
>                 exit
>         elif [ "$ans" != "" -a "$ans" != "y" ];then
>                 echo "Invalid entry..."
>         else
>                 break
>         fi
> done
Would you like the script to check the second box ([y]n)?
asdfad
Invalid entry...
Would you like the script to check the second box ([y]n)?

[root@lvs ~]# while true;do
> echo "Would you like the script to check the second box ([y]n)?"
> read ans
>         if [ "$ans" = "n" ];then
>                 echo
>                 echo "bye!"
>                 exit
>         elif [ "$ans" != "" -a "$ans" != "y" ];then
>                 echo "Invalid entry..."
>         else
>                 break
>         fi
> done
Would you like the script to check the second box ([y]n)?
y
[root@lvs ~]# while true;do
> echo "Would you like the script to check the second box ([y]n)?"
> read ans
>         if [ "$ans" = "n" ];then
>                 echo
>                 echo "bye!"
>                 exit
>         elif [ "$ans" != "" -a "$ans" != "y" ];then
>                 echo "Invalid entry..."
>         else
>                 break
>         fi
> done
Would you like the script to check the second box ([y]n)?
n

logout
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T17:34:26+00:00Added an answer on June 11, 2026 at 5:34 pm

    The problem is that : [ “$ans” != “” -o “$ans” != “y” ] is always true because of the or and the negation. $ans cannot be equal to “” and to “y”.

    Try replace these lines

    if [ "$ans" == "n" ];then 
    elif [ "$ans" != "" -o "$ans" != "y" ];then 
    

    by these

    if [ "$ans" = "n" ];then 
    elif [ "$ans" != "" -a "$ans" != "y" ];then 
    

    or these

    if [[ $ans == n ]];then 
    elif [[ $ans != "" && $ans != y ]];then 
    

    The easier is to do is a case:

    case $ans in
      y) echo "yes"
      ;;
      n) echo "no"
      ;;
      *)
      ;;
     esac
    

    also break must be used only in a for or while loop, or in a select but it is missing in your post .

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been looking for a way to accomplish this but can't seem to find
I'm not looking to keyword spam here, and this question is in the least
I'm not looking to harvest information, I'm just trying to create a way to
edit: I'm not looking for you to debug this code. If you are familiar
I am looking for the most efficient/direct way to do this simple C/C++ operation:
I'm looking for a better way to this. I have a chunk of code
I'm working with ITextSharp for a project and am looking for a reasonable way
I am looking for a way to pass a method by reference. I understand
well I am not looking for how to draw items on 2d Graph, Its
I'm not looking for how, I'm looking for why? I couldn't find a straight

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.