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

  • Home
  • SEARCH
  • 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 7556539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:53:00+00:00 2026-05-30T11:53:00+00:00

I am writing a script in ksh which needs to check a variable is

  • 0

I am writing a script in ksh which needs to check a variable is set to one of the two accepted values. I have got the following code but when I enter a valid value e.g. “C” I get the error message (Not a valid value):

if  [[ "$Mode" != "C" ]] || [[ "$Mode" != "M" ]] 
then

   echo ""
   echo "*Not a valid value*"

   exit 2;

fi

I am not sure why it is failing on the string comparison, I have tried varations on syntax but still not getting anywhere, any help would be much appreciated.

  • 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-05-30T11:53:02+00:00Added an answer on May 30, 2026 at 11:53 am
    if ! [[  "$Mode" == "C" || "$Mode" == "M" ]] ; then
       echo ""
       echo "*Not a valid value*"
       exit 2;
    fi
    

    I think this is the easier way to test multiple values. I like to think of it ‘if Mode is NOT in the list of C, or M, or ….; then ….’ I see beginners post code like yours (and I did it myself when I was a beginner), because then your mental model is ‘if Mode is NOT C OR Mode is NOT M then …’, but you you really need the ‘AND’ instead (as illustrated by jlliagre).

    I hope this helps.

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

Sidebar

Related Questions

I writing a ksh shell script and I have long comma separated string that
I'm writing a ksh script and apparently have an unmatched double quote ( )
I'm writing a ksh script and I have to run a executable at a
I am writing a script which is likely to be modified by users. Currently
I'm writing a script in python which basically queries WMI and updates the information
I'm writing a script which is to be executed hourly. It basically works as:
at the moment I'm writing a simple script in ksh who should take some
I'm writing a script to check for dos line breaks, in a unix environment.
I'm writing a script that has to do something like this at one point:
I am writing a script that will transfer a file from one server to

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.