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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:22:24+00:00 2026-05-11T18:22:24+00:00

So basically I am trying to check the arguments that are passed into the

  • 0

So basically I am trying to check the arguments that are passed into the script. If it has three arguments and the third argument is a 1, then I want it to continue. I also want it to continue if it has four arguments and the third argument is not a 1.

So basically I thought that I could just do…

if ([ $# -ne 3 ] and [ "$3" -ne "2" ])
then
exit 0
fi

However it seems that Bash does not have and’s to use for if’s,so then I figured that I could just use nested if’s, however now it’s complaining still. So this is what I have currently…

if [ $# -ne 3 ]
then
if [ "$3" -ne "1" ]
then

echo "Improper number of arguments.
FORMAT make-csv-data <STUDY> <TAG> <MODE> <SELECT>

Select can be left off if you want all data (Mode=1)
"
exit 0

fi
fi
if [ $# -ne 4 ]
then
if [ "$3" -ne "2" ]
then

echo "Improper number of arguments.
FORMAT make-csv-data <STUDY> <TAG> <MODE> <SELECT>

Select can be left off if you want all data (Mode=1)
"
exit 0

fi
fi

So where am I going wrong? Can I not nest if statements in Bash? Is there a super-zen way of doing this that I’m missing altogether?

Thanks for the any help you could give me.


New Problem…

Now, for some reason or another, the code isn’t working at all. There are no errors or anything, it just doesn’t work. It doesn’t check the number of arguments. I’ve run the script with no arguments at all and it just skips it like it’s not even there.

Weird part is that I was sure that the code was working yesterday. Come back today, not so much. Any ideas on what the problem is? (Sorry, but I have to remove the accepted answer on this.)

if [[ $# = 3 && "$3" != "1" ]]
then

echo "Improper number of arguments.
FORMAT make-csv-data <STUDY> <TAG> <MODE> <SELECT>

Select can be omitted if all data is required (Mode=1)
"
exit 0

fi

if [[ $# > 4 ]]
then

echo "Improper number of arguments.
FORMAT make-csv-data <STUDY> <TAG> <MODE> <SELECT>

Select can be omitted if all data is required (Mode=1)
"
exit 0

fi

EDIT II:

There are a few things that the Bash shell isn’t liking about this script that I’m trying to do. I’ll probably end up rewriting it in another scripting language and do a few more things that I have in mind for the project. Thanks for the help in any case.

  • 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-11T18:22:24+00:00Added an answer on May 11, 2026 at 6:22 pm
    if [ $# -ne 3 -a "$3" -ne "1" ]; then
      exit 0
    fi
    

    For reference

    -a = and
    -o = or
    

    Or, you could just use use:

    if [[ $# != 3 && "$3" != "1" ]]; then
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically what I'm trying to accomplish is I want to check multiple dynamic forms
I'm basically trying to teach myself how to code and I want to follow
Basically I'm trying to accomplish the same thing that mailto:bgates@microsoft.com does in Internet Explorer
Basically, I'm trying to tap into the Soap pipeline in .NET 2.0 - I
I am trying to create a script that checks if a certain value is
I'm trying to write a script which basically takes an array of lots of
Basically I'm trying to check if anything is in stdin when the program is
I'm trying to type-check the commands I want to send to a server from
I'm basically trying to figure out the simplest way to perform your basic insert
I recently came across this in some code - basically someone trying to create

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.