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 7568031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:49:14+00:00 2026-05-30T14:49:14+00:00

I can seem to see why this doesn’t work: #!/bin/bash if [ $# -ne

  • 0

I can seem to see why this doesn’t work:

#!/bin/bash

if [ $# -ne 1 ] || [ $# -ne 2 ]; then 
# Should run if there are either 1 or 2 options specified
  echo "usage: ${0##*/} <username>"
  exit
fi

When testing to see if it works:

root@ubuntu:~# testing.sh optionone optiontwo
...Correct output...
root@ubuntu:~# testing.sh optionone
usage: testing.sh <username>
  • 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-30T14:49:15+00:00Added an answer on May 30, 2026 at 2:49 pm

    Note that you are executing 2 commands in:

    [ $# -ne 1 ] || [ $# -ne 2 ]
    

    [ $# -ne 1 ] is a 1st command, and the [ $# -ne 2 ] command is executed only if the previous has a non-zero error code as of the || shell operator.

    In your case, it is not important, but in the case bellow, it is:

    [ $? -eq 0 ] || [ $? -eq 1 ]
    

    The 2nd command will always be true, as the 2nd $? is the return code of [ $? -eq 0 ]. You can test it with the lines bellow that will print true twice:

    function f() { return $1; }
    f 1
    { [ $? -eq 0 ] || [ $? -eq 1 ]; } && echo "true"
    f 2
    { [ $? -eq 0 ] || [ $? -eq 1 ]; } && echo "true"
    

    The correct way to execute a or in a single command is:

    [ $? -eq 0 -o $? -eq 1 ]
    

    This way, those bellow only print true once:

    function f() { return $1; }
    f 1
    { [ $? -eq 0 -o $? -eq 1 ]; } && echo "true"
    f 2
    { [ $? -eq 0 -o $? -eq 1 ]; } && echo "true"
    

    And concerning your original question, kev has already point out that there was a logic error in your test. The negative of [ $# -eq 1 ] || [ $# -eq 2 ] is NOT [ $# -eq 1 ] && NOT [ $# -eq 2 ] and this becomes [ $# -ne 1 ] && [ $# -ne 2 ] or in a single command:

    [ $# -ne 1 -a $# -ne 2 ]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can't seem to figure this out, see code below. Trying to make a GET
I see there is version 1.5 and 3.0 beta , but I can't seem
I can't seem to see the forest for the trees right now (Looked at
Can't seem to find a way to do this, google is failing me! Please
can't seem to find a way to do this anywhere. I have an SQL
Can't seem to achieve this simple functionality! All I want is to clear a
I can't seem to find that option. Surely it's in there?
This problem doesn't seem browser specific and generally applies to style in the webkit/gecko/mozilla
can't seem to get the syntax right in order to pass the AttID variable.
I can't seem to find details on how to unsubscribe from ubiquity commands. The

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.