bash - command line arguments to script
<p>hello all newbie here :D</p>

<p>i am working on a project right now which involves a script that handles a *.dat file.The script runs under specific commands inputed by user</p>

<p>my problem is that i cant figure out how to "grab" the arguments from the command to "import" them to the script</p>

<p>here are some examples from the specific commands : </p>

<ol>
<li><p><code>./tool.sh -f &lt;file&gt;</code></p></li>
<li><p><code>./tool.sh -f &lt;file&gt; -id &lt;id&gt;</code></p></li>
<li><p><code>./tool.sh --born-since &lt;dateA&gt; --born-until &lt;dateB&gt; -f &lt;file&gt;</code></p></li>
</ol>

<p>where tool.sh is the scripts name, <code>&lt;file&gt;</code> is the <code>*.dat</code> file, <code>&lt;date&gt;</code> is just a date in this format YYYY-MM-DD</p>

<p>so as you can see there are both shortwords and longwords. I know that the getopts command is tricky to handle the long ones. How can i handle all of them using a "single" piece of code?</p>

<p>edit: i need to use the arguments and the conditional expressions for a case using the "if"</p>

<p>so could i just do :</p>

<pre><code>#!/bin/bash 
getopts f a
if [ $1 == "something" &amp;&amp; $2 == "something2" &amp;&amp; $a == "f" ]; then
....
elif [ $1 == "something3" &amp;&amp; $2 == "something4" &amp;&amp; $a == "f" ]
....
else 
....
fi
</code></pre>

<p>would that be correct?</p>