<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: The 60 second getopts tutorial</title>
	<atom:link href="http://bashcurescancer.com/the-60-second-getopts-tutorial.html/feed" rel="self" type="application/rss+xml" />
	<link>http://bashcurescancer.com/the-60-second-getopts-tutorial.html</link>
	<description>Learn the UNIX/Linux command line</description>
	<lastBuildDate>Mon, 06 Jun 2011 01:35:32 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Cheap Computers</title>
		<link>http://bashcurescancer.com/the-60-second-getopts-tutorial.html/comment-page-1#comment-37076</link>
		<dc:creator>Cheap Computers</dc:creator>
		<pubDate>Wed, 10 Feb 2010 17:01:27 +0000</pubDate>
		<guid isPermaLink="false">http://bashcurescancer.com/the-60-second-getopts-tutorial.html#comment-37076</guid>
		<description>Very informative article. I’ve found your blog via Yahoo and I’m really glad about the information you provide in your posts.</description>
		<content:encoded><![CDATA[<p>Very informative article. I’ve found your blog via Yahoo and I’m really glad about the information you provide in your posts.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris F.A. Johnson</title>
		<link>http://bashcurescancer.com/the-60-second-getopts-tutorial.html/comment-page-1#comment-34512</link>
		<dc:creator>Chris F.A. Johnson</dc:creator>
		<pubDate>Mon, 14 Dec 2009 16:54:57 +0000</pubDate>
		<guid isPermaLink="false">http://bashcurescancer.com/the-60-second-getopts-tutorial.html#comment-34512</guid>
		<description>&quot;‘/bin/*.sh’ will always have to be enclosed in single quotes, since bash will always try to expand it to a list of filenames if you don’t.&quot;

It will not be expanded inside any quotes, single or double.


&quot;collect $* and pass it to the function that you want to run getopts from&quot;

No, you pass &quot;$@&quot; (with the quotes).</description>
		<content:encoded><![CDATA[<p>&#8220;‘/bin/*.sh’ will always have to be enclosed in single quotes, since bash will always try to expand it to a list of filenames if you don’t.&#8221;</p>
<p>It will not be expanded inside any quotes, single or double.</p>
<p>&#8220;collect $* and pass it to the function that you want to run getopts from&#8221;</p>
<p>No, you pass &#8220;$@&#8221; (with the quotes).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bun</title>
		<link>http://bashcurescancer.com/the-60-second-getopts-tutorial.html/comment-page-1#comment-33390</link>
		<dc:creator>bun</dc:creator>
		<pubDate>Wed, 11 Nov 2009 07:34:39 +0000</pubDate>
		<guid isPermaLink="false">http://bashcurescancer.com/the-60-second-getopts-tutorial.html#comment-33390</guid>
		<description>$ 1 thing &#039;getopts&#039; doesn&#039;t offer is a way to specify optional arg. &#039;getopt&#039; is the solution, it&#039;s an external tool.
$ it&#039;s used differently, mainly it isn&#039;t designed to be used directly as condition in loop
$ a tricky part is that to denote that a param is to be treated as opt arg, not script arg, is that for single char opt, there&#039;s no space between the opt &amp; the arg, for long opt, it&#039;s the usual</description>
		<content:encoded><![CDATA[<p>$ 1 thing &#8216;getopts&#8217; doesn&#8217;t offer is a way to specify optional arg. &#8216;getopt&#8217; is the solution, it&#8217;s an external tool.<br />
$ it&#8217;s used differently, mainly it isn&#8217;t designed to be used directly as condition in loop<br />
$ a tricky part is that to denote that a param is to be treated as opt arg, not script arg, is that for single char opt, there&#8217;s no space between the opt &amp; the arg, for long opt, it&#8217;s the usual</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: intech_guy</title>
		<link>http://bashcurescancer.com/the-60-second-getopts-tutorial.html/comment-page-1#comment-32230</link>
		<dc:creator>intech_guy</dc:creator>
		<pubDate>Wed, 26 Aug 2009 06:47:59 +0000</pubDate>
		<guid isPermaLink="false">http://bashcurescancer.com/the-60-second-getopts-tutorial.html#comment-32230</guid>
		<description>In response to rubin427:

That makes sense from both a general programming and bash perspective. The $# and associated variables are relative to scope.

You will return all the command line parameters when examining $# from the main body, with $0 being the executed script name as called.

When checking $# from within a function it will return the function arguments (if any) with the function name (=$0).</description>
		<content:encoded><![CDATA[<p>In response to rubin427:</p>
<p>That makes sense from both a general programming and bash perspective. The $# and associated variables are relative to scope.</p>
<p>You will return all the command line parameters when examining $# from the main body, with $0 being the executed script name as called.</p>
<p>When checking $# from within a function it will return the function arguments (if any) with the function name (=$0).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pierce.jason</title>
		<link>http://bashcurescancer.com/the-60-second-getopts-tutorial.html/comment-page-1#comment-31840</link>
		<dc:creator>pierce.jason</dc:creator>
		<pubDate>Wed, 29 Jul 2009 07:44:08 +0000</pubDate>
		<guid isPermaLink="false">http://bashcurescancer.com/the-60-second-getopts-tutorial.html#comment-31840</guid>
		<description>rubin: Your conclusion is correct. What you can do, is collect $* and pass it to the function that you want to run getopts from. Otherwise getopts examines the arguements to the function that it is ran from. This can be usefull for allowing a functions syntax to mirror that of an external program.</description>
		<content:encoded><![CDATA[<p>rubin: Your conclusion is correct. What you can do, is collect $* and pass it to the function that you want to run getopts from. Otherwise getopts examines the arguements to the function that it is ran from. This can be usefull for allowing a functions syntax to mirror that of an external program.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: passing arguments - Shell Programming and Scripting - The UNIX and Linux Forums</title>
		<link>http://bashcurescancer.com/the-60-second-getopts-tutorial.html/comment-page-1#comment-30632</link>
		<dc:creator>passing arguments - Shell Programming and Scripting - The UNIX and Linux Forums</dc:creator>
		<pubDate>Tue, 19 May 2009 17:06:09 +0000</pubDate>
		<guid isPermaLink="false">http://bashcurescancer.com/the-60-second-getopts-tutorial.html#comment-30632</guid>
		<description>[...] command -o arg1 -p -q arg2 &lt;arg for command&gt;  Options start with a - and may or may not have arguments, plus they can occur in any order. Hence getopts  getopts tutorial - The 60 second getopts tutorial [...]</description>
		<content:encoded><![CDATA[<p>[...] command -o arg1 -p -q arg2 &lt;arg for command&gt;  Options start with a &#8211; and may or may not have arguments, plus they can occur in any order. Hence getopts  getopts tutorial &#8211; The 60 second getopts tutorial [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: hyperion</title>
		<link>http://bashcurescancer.com/the-60-second-getopts-tutorial.html/comment-page-1#comment-29817</link>
		<dc:creator>hyperion</dc:creator>
		<pubDate>Tue, 07 Apr 2009 18:53:35 +0000</pubDate>
		<guid isPermaLink="false">http://bashcurescancer.com/the-60-second-getopts-tutorial.html#comment-29817</guid>
		<description>How does the optstring look for optional flags I need to achieve this:

script.sh -(e&#124;d) -i &#039;//&#039; -o // -p 

I have resigned to the fact that the -i flag&#039;s value, let&#039;s say &#039;/bin/*.sh&#039; will always have to be enclosed in single quotes, since bash will always try to expand it to a list of filenames if you don&#039;t.</description>
		<content:encoded><![CDATA[<p>How does the optstring look for optional flags I need to achieve this:</p>
<p>script.sh -(e|d) -i &#8216;//&#8217; -o // -p </p>
<p>I have resigned to the fact that the -i flag&#8217;s value, let&#8217;s say &#8216;/bin/*.sh&#8217; will always have to be enclosed in single quotes, since bash will always try to expand it to a list of filenames if you don&#8217;t.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Lefflre</title>
		<link>http://bashcurescancer.com/the-60-second-getopts-tutorial.html/comment-page-1#comment-29490</link>
		<dc:creator>Jonathan Lefflre</dc:creator>
		<pubDate>Sat, 21 Mar 2009 18:48:47 +0000</pubDate>
		<guid isPermaLink="false">http://bashcurescancer.com/the-60-second-getopts-tutorial.html#comment-29490</guid>
		<description>Responding to rubin427: getopts is an odd built-in function that implicitly processes &quot;$@&quot;, and &quot;$@&quot; inside a function means the arguments to the function rather the arguments to the script as a whole.  Unless you pass &quot;$@&quot; to the function that processes getopts, you are unlikely to be successful.

This script works (both ksh and bash - the (a) notation in the case does not work in classic Bourne shell, but the rest does):

    #!bin/ksh

    aflag=0
    bflag=0
    ffile=&quot;&quot;

    somefunc()
    {
        echo &quot;somefunc: $*&quot;
        while getopts &quot;abf:&quot; x
        do
            case $x in
            (a) aflag=1;;
            (b) bflag=1;;
            (f) ffile=&quot;$OPTARG&quot;;;
            (*) echo &quot;Dunno!&quot; 1&gt;&amp;2; exit 1;;
            esac
        done
    }

    somefunc &quot;$@&quot;

    echo &quot;aflag=$aflag&quot;
    echo &quot;bflag=$bflag&quot;
    echo &quot;ffile=$ffile&quot;</description>
		<content:encoded><![CDATA[<p>Responding to rubin427: getopts is an odd built-in function that implicitly processes &#8220;$@&#8221;, and &#8220;$@&#8221; inside a function means the arguments to the function rather the arguments to the script as a whole.  Unless you pass &#8220;$@&#8221; to the function that processes getopts, you are unlikely to be successful.</p>
<p>This script works (both ksh and bash &#8211; the (a) notation in the case does not work in classic Bourne shell, but the rest does):</p>
<p>    #!bin/ksh</p>
<p>    aflag=0<br />
    bflag=0<br />
    ffile=&#8221;"</p>
<p>    somefunc()<br />
    {<br />
        echo &#8220;somefunc: $*&#8221;<br />
        while getopts &#8220;abf:&#8221; x<br />
        do<br />
            case $x in<br />
            (a) aflag=1;;<br />
            (b) bflag=1;;<br />
            (f) ffile=&#8221;$OPTARG&#8221;;;<br />
            (*) echo &#8220;Dunno!&#8221; 1&gt;&amp;2; exit 1;;<br />
            esac<br />
        done<br />
    }</p>
<p>    somefunc &#8220;$@&#8221;</p>
<p>    echo &#8220;aflag=$aflag&#8221;<br />
    echo &#8220;bflag=$bflag&#8221;<br />
    echo &#8220;ffile=$ffile&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ken</title>
		<link>http://bashcurescancer.com/the-60-second-getopts-tutorial.html/comment-page-1#comment-29036</link>
		<dc:creator>Ken</dc:creator>
		<pubDate>Wed, 04 Mar 2009 21:20:21 +0000</pubDate>
		<guid isPermaLink="false">http://bashcurescancer.com/the-60-second-getopts-tutorial.html#comment-29036</guid>
		<description>What is $badOptionHelp set to? It doesn&#039;t seem to be automatically set like OPTARG.

For that matter, you seem to assume that function printHelpAndExit exists.</description>
		<content:encoded><![CDATA[<p>What is $badOptionHelp set to? It doesn&#8217;t seem to be automatically set like OPTARG.</p>
<p>For that matter, you seem to assume that function printHelpAndExit exists.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aaditya Bhatia</title>
		<link>http://bashcurescancer.com/the-60-second-getopts-tutorial.html/comment-page-1#comment-28849</link>
		<dc:creator>Aaditya Bhatia</dc:creator>
		<pubDate>Mon, 23 Feb 2009 09:32:04 +0000</pubDate>
		<guid isPermaLink="false">http://bashcurescancer.com/the-60-second-getopts-tutorial.html#comment-28849</guid>
		<description>Thanks for this concise tutorial! It helped.</description>
		<content:encoded><![CDATA[<p>Thanks for this concise tutorial! It helped.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.523 seconds -->
<!-- Cached page served by WP-Cache -->

