<p>Say, I have a script that gets called with this line:</p>
<pre><code>./myscript -vfd ./foo/bar/someFile -o /fizz/someOtherFile
</code></pre>
<p>or this one:</p>
<pre><code>./myscript -v -f -d -o /fizz/someOtherFile ./foo/bar/someFile 
</code></pre>
<p>What's the accepted way of parsing this such that in each case (or some combination of the two) <code>$v</code>, <code>$f</code>, and  <code>$d</code> will all be set to <code>true</code> and <code>$outFile</code> will be equal to <code>/fizz/someOtherFile</code>?</p>

```
getopt()
```
/
```
getopts()
```
is a good option.  Copied from
here
:
The simple use of "getopt" is shown in this mini-script:
```
```
#!/bin/bash
echo "Before getopt"
for i
do
  echo $i
done
args=`getopt abc:d $*`
set -- $args
echo "After getopt"
for i
do
  echo "-->$i"
done
```
```
What we have said is that any of -a,
-b, -c or -d will be allowed, but that -c is followed by an argument (the "c:" says that).
If we call this "g" and try it out:
```
```
bash-2.05a$ ./g -abc foo
Before getopt
-abc
foo
After getopt
-->-a
-->-b
-->-c
-->foo
-->--
```
```
We start with two arguments, and
"getopt" breaks apart the options and
puts each in its own argument. It also
added "--".