Shell: Set optional argument or use default value using getopts?
<p>I'm trying to get the following as valid calls of my script:</p>

<pre><code>sh name.sh -l -a
sh name.sh -l
</code></pre>

<p>This is the code I have so far using getopts, where -a is an required argument:</p>

<pre><code>default="no"

echo "Initial parameters. 

while getopts ":l:a:" o; do
    case "${o}" in
        l)
            ...;;
        a)
            a+=(${OPTARG})
            IFS=',' read -a myarray &lt;&lt;&lt; "$a"
            default="yes"
            ;;
        :)
            echo "Missing option argument for -$OPTARG" &gt;&amp;2; exit 1;;
        *)
            usage;;
    esac
done
shift $((OPTIND-1))

if [ -z "${l}" ] || [ -z "${a}" ] ; then
    usage
fi
</code></pre>

<p>I just need to know how to set in getopts the optional flag -a with it's argument. 
Thanks:)</p>