title: Argument Checking Problem in Bash Script
body: <p>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.</p>
  
  <p>So basically I thought that I could just do...</p>
  
  <pre><code>if ([ $# -ne 3 ] and [ "$3" -ne "2" ])
  then
  exit 0
  fi
  </code></pre>
  
  <p>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...</p>
  
  <pre><code>if [ $# -ne 3 ]
  then
  if [ "$3" -ne "1" ]
  then
  
  echo "Improper number of arguments.
  FORMAT make-csv-data &lt;STUDY&gt; &lt;TAG&gt; &lt;MODE&gt; &lt;SELECT&gt;
  
  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 &lt;STUDY&gt; &lt;TAG&gt; &lt;MODE&gt; &lt;SELECT&gt;
  
  Select can be left off if you want all data (Mode=1)
  "
  exit 0
  
  fi
  fi
  </code></pre>
  
  <p>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?</p>
  
  <p>Thanks for the any help you could give me.</p>
  
  <hr>
  
  <p>New Problem...</p>
  
  <p>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.  </p>
  
  <p>Weird part is that I was <em>sure</em> 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.)  </p>
  
  <pre><code>if [[ $# = 3 &amp;&amp; "$3" != "1" ]]
  then
  
  echo "Improper number of arguments.
  FORMAT make-csv-data &lt;STUDY&gt; &lt;TAG&gt; &lt;MODE&gt; &lt;SELECT&gt;
  
  Select can be omitted if all data is required (Mode=1)
  "
  exit 0
  
  fi
  
  if [[ $# &gt; 4 ]]
  then
  
  echo "Improper number of arguments.
  FORMAT make-csv-data &lt;STUDY&gt; &lt;TAG&gt; &lt;MODE&gt; &lt;SELECT&gt;
  
  Select can be omitted if all data is required (Mode=1)
  "
  exit 0
  
  fi
  </code></pre>
  
  <p>EDIT II:  </p>
  
  <p>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.</p>