<?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: Command line arguments in bash scripts</title>
	<atom:link href="http://blog.apokalyptik.com/2008/07/07/command-line-arguments-in-bash-scripts/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.apokalyptik.com/2008/07/07/command-line-arguments-in-bash-scripts/</link>
	<description>The random things that spew forth from my brain...</description>
	<lastBuildDate>Fri, 05 Mar 2010 04:22:45 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=3.0-alpha</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: anonymous</title>
		<link>http://blog.apokalyptik.com/2008/07/07/command-line-arguments-in-bash-scripts/comment-page-1/#comment-8268</link>
		<dc:creator>anonymous</dc:creator>
		<pubDate>Sun, 25 Jan 2009 23:18:13 +0000</pubDate>
		<guid isPermaLink="false">http://blog.apokalyptik.com/?p=292#comment-8268</guid>
		<description>He&#039;s right, y&#039;know.

getopt works quite marvelously, and re-inventing the wheel is pretty retarded.

Six levels of nesting, just to parse parameters looks like a maintainability nightmare, compared to a single, simple while/case loop.</description>
		<content:encoded><![CDATA[<p>He&#8217;s right, y&#8217;know.</p>
<p>getopt works quite marvelously, and re-inventing the wheel is pretty retarded.</p>
<p>Six levels of nesting, just to parse parameters looks like a maintainability nightmare, compared to a single, simple while/case loop.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Toki</title>
		<link>http://blog.apokalyptik.com/2008/07/07/command-line-arguments-in-bash-scripts/comment-page-1/#comment-8001</link>
		<dc:creator>Toki</dc:creator>
		<pubDate>Wed, 10 Dec 2008 21:29:06 +0000</pubDate>
		<guid isPermaLink="false">http://blog.apokalyptik.com/?p=292#comment-8001</guid>
		<description>Thank you:)</description>
		<content:encoded><![CDATA[<p>Thank you:)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: apokalyptik</title>
		<link>http://blog.apokalyptik.com/2008/07/07/command-line-arguments-in-bash-scripts/comment-page-1/#comment-7939</link>
		<dc:creator>apokalyptik</dc:creator>
		<pubDate>Tue, 18 Nov 2008 20:24:58 +0000</pubDate>
		<guid isPermaLink="false">http://blog.apokalyptik.com/?p=292#comment-7939</guid>
		<description>@Doug -- Why thanks. I especially appreciate the retarded bit. Cheers!</description>
		<content:encoded><![CDATA[<p>@Doug &#8212; Why thanks. I especially appreciate the retarded bit. Cheers!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: fabricio</title>
		<link>http://blog.apokalyptik.com/2008/07/07/command-line-arguments-in-bash-scripts/comment-page-1/#comment-7936</link>
		<dc:creator>fabricio</dc:creator>
		<pubDate>Mon, 17 Nov 2008 15:41:26 +0000</pubDate>
		<guid isPermaLink="false">http://blog.apokalyptik.com/?p=292#comment-7936</guid>
		<description>Here&#039;s yet another take on it:

http://codesnippets.joyent.com/posts/show/1697</description>
		<content:encoded><![CDATA[<p>Here&#8217;s yet another take on it:</p>
<p><a href="http://codesnippets.joyent.com/posts/show/1697" rel="nofollow">http://codesnippets.joyent.com/posts/show/1697</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Doug</title>
		<link>http://blog.apokalyptik.com/2008/07/07/command-line-arguments-in-bash-scripts/comment-page-1/#comment-7931</link>
		<dc:creator>Doug</dc:creator>
		<pubDate>Thu, 13 Nov 2008 17:55:48 +0000</pubDate>
		<guid isPermaLink="false">http://blog.apokalyptik.com/?p=292#comment-7931</guid>
		<description>This is a pretty retarded and feature-lacking re-invention of the wheel. Seriously:

help getopt;

It&#039;s a bash built-in (and mostly compatible binaries that the built-in was based off of exist on any sane system even without bash!).

Example usage:

# Parse commandline options.
GETOPT=&quot;$(getopt -o c:olhdfs --long children:,stdout,syslog,help,dry-run,force,status -n &quot;$0&quot; -- &quot;$@&quot;)&quot;
if [ &quot;$?&quot; -gt &#039;0&#039; ]; then
  echo &quot;$USAGE&quot;
  exit 1
fi

eval set -- &quot;$GETOPT&quot;

while true; do
  case &quot;$1&quot; in
    -h&#124;--help) echo &quot;$USAGE&quot;; exit 0 ;;
    -c&#124;--children) if [ &quot;$2&quot; -gt &#039;0&#039; ] &gt;/dev/null 2&gt;&1; then
                    MAXCHILDREN=&quot;$2&quot;;
                    shift;
                    shift;
                  else
                    echo &quot;Number of children MUST be an integer.&quot;;
                    exit 1;
                  fi
                    ;;
    -o&#124;--stdout) TTYOUT=1; shift ;;
    -l&#124;--syslog) SYSLOGOUT=1; shift ;;
    -d&#124;--dry-run) TTYOUT=1; DRYRUN=1; shift ;;
    -s&#124;--status) TTYOUT=1; STATUSONLY=1; shift ;;
    -f&#124;--force) FORCE=1; shift ;;
    --) shift; break ;;
    *) echo &quot;Invalid Option ${1}.&quot;; echo &quot;$USAGE&quot;; exit 1 ;;
  esac
done</description>
		<content:encoded><![CDATA[<p>This is a pretty retarded and feature-lacking re-invention of the wheel. Seriously:</p>
<p>help getopt;</p>
<p>It&#8217;s a bash built-in (and mostly compatible binaries that the built-in was based off of exist on any sane system even without bash!).</p>
<p>Example usage:</p>
<p># Parse commandline options.<br />
GETOPT=&#8221;$(getopt -o c:olhdfs &#8211;long children:,stdout,syslog,help,dry-run,force,status -n &#8220;$0&#8243; &#8212; &#8220;$@&#8221;)&#8221;<br />
if [ "$?" -gt '0' ]; then<br />
  echo &#8220;$USAGE&#8221;<br />
  exit 1<br />
fi</p>
<p>eval set &#8212; &#8220;$GETOPT&#8221;</p>
<p>while true; do<br />
  case &#8220;$1&#8243; in<br />
    -h|&#8211;help) echo &#8220;$USAGE&#8221;; exit 0 ;;<br />
    -c|&#8211;children) if [ "$2" -gt '0' ] &gt;/dev/null 2&gt;&amp;1; then<br />
                    MAXCHILDREN=&#8221;$2&#8243;;<br />
                    shift;<br />
                    shift;<br />
                  else<br />
                    echo &#8220;Number of children MUST be an integer.&#8221;;<br />
                    exit 1;<br />
                  fi<br />
                    ;;<br />
    -o|&#8211;stdout) TTYOUT=1; shift ;;<br />
    -l|&#8211;syslog) SYSLOGOUT=1; shift ;;<br />
    -d|&#8211;dry-run) TTYOUT=1; DRYRUN=1; shift ;;<br />
    -s|&#8211;status) TTYOUT=1; STATUSONLY=1; shift ;;<br />
    -f|&#8211;force) FORCE=1; shift ;;<br />
    &#8211;) shift; break ;;<br />
    *) echo &#8220;Invalid Option ${1}.&#8221;; echo &#8220;$USAGE&#8221;; exit 1 ;;<br />
  esac<br />
done</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bookmarks about Scripts</title>
		<link>http://blog.apokalyptik.com/2008/07/07/command-line-arguments-in-bash-scripts/comment-page-1/#comment-7910</link>
		<dc:creator>Bookmarks about Scripts</dc:creator>
		<pubDate>Sat, 27 Sep 2008 03:15:04 +0000</pubDate>
		<guid isPermaLink="false">http://blog.apokalyptik.com/?p=292#comment-7910</guid>
		<description>[...] - bookmarked by 1 members originally found by showwhat on 2008-09-09  Command line arguments in bash scripts  http://blog.apokalyptik.com/2008/07/07/command-line-arguments-in-bash-scripts/ - bookmarked by 6 [...]</description>
		<content:encoded><![CDATA[<p>[...] &#8211; bookmarked by 1 members originally found by showwhat on 2008-09-09  Command line arguments in bash scripts  <a href="http://blog.apokalyptik.com/2008/07/07/command-line-arguments-in-bash-scripts/" rel="nofollow">http://blog.apokalyptik.com/2008/07/07/command-line-arguments-in-bash-scripts/</a> &#8211; bookmarked by 6 [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bothie</title>
		<link>http://blog.apokalyptik.com/2008/07/07/command-line-arguments-in-bash-scripts/comment-page-1/#comment-7899</link>
		<dc:creator>bothie</dc:creator>
		<pubDate>Fri, 22 Aug 2008 16:03:02 +0000</pubDate>
		<guid isPermaLink="false">http://blog.apokalyptik.com/?p=292#comment-7899</guid>
		<description>&gt;&gt;&gt; For this reason the script should be updates to allow for arguments like “–arguments=–foo”

Watching closer on the script I discovered, that the script already support that style of arguments.

However, it doesn&#039;t support other things. Imagine

mv -i oldname newname

This would lead to i=oldname and newname -&gt; ???

In short: This script helps in parsing command line options, but it isn&#039;t the non-plus-ultra yet.

Regards, Bodo</description>
		<content:encoded><![CDATA[<p>&gt;&gt;&gt; For this reason the script should be updates to allow for arguments like “–arguments=–foo”</p>
<p>Watching closer on the script I discovered, that the script already support that style of arguments.</p>
<p>However, it doesn&#8217;t support other things. Imagine</p>
<p>mv -i oldname newname</p>
<p>This would lead to i=oldname and newname -&gt; ???</p>
<p>In short: This script helps in parsing command line options, but it isn&#8217;t the non-plus-ultra yet.</p>
<p>Regards, Bodo</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bothie</title>
		<link>http://blog.apokalyptik.com/2008/07/07/command-line-arguments-in-bash-scripts/comment-page-1/#comment-7898</link>
		<dc:creator>bothie</dc:creator>
		<pubDate>Thu, 21 Aug 2008 14:33:07 +0000</pubDate>
		<guid isPermaLink="false">http://blog.apokalyptik.com/?p=292#comment-7898</guid>
		<description>Oh, and another thing.

@Milian Wolff:

It doesn&#039;t make a difference if you write

run.sh --file &quot;foobar&quot; --arguments &quot;--foo&quot;

or if you write

run.sh --file &quot;foobar&quot; --arguments --foo

For this reason the script should be updates to allow for arguments like &quot;--arguments=--foo&quot;

Regards, Bodo</description>
		<content:encoded><![CDATA[<p>Oh, and another thing.</p>
<p>@Milian Wolff:</p>
<p>It doesn&#8217;t make a difference if you write</p>
<p>run.sh &#8211;file &#8220;foobar&#8221; &#8211;arguments &#8220;&#8211;foo&#8221;</p>
<p>or if you write</p>
<p>run.sh &#8211;file &#8220;foobar&#8221; &#8211;arguments &#8211;foo</p>
<p>For this reason the script should be updates to allow for arguments like &#8220;&#8211;arguments=&#8211;foo&#8221;</p>
<p>Regards, Bodo</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bothie</title>
		<link>http://blog.apokalyptik.com/2008/07/07/command-line-arguments-in-bash-scripts/comment-page-1/#comment-7897</link>
		<dc:creator>bothie</dc:creator>
		<pubDate>Thu, 21 Aug 2008 14:30:35 +0000</pubDate>
		<guid isPermaLink="false">http://blog.apokalyptik.com/?p=292#comment-7897</guid>
		<description>Two comments:

1. Instead of

	OIFS=$IFS; IFS=$(echo -e &quot;\n&quot;); getopt $@; IFS=$OIFS

you could also just write

	getopt &quot;$@&quot;

2. It may be a security problem if the getopt function may write any variable in the normal namespace of the script. So, it&#039;s better to prefix each variable by e.g. &quot;arg_&quot;. So --name bothie won&#039;t get name=&quot;bothie&quot; but arg_name=&quot;bothie&quot;.

Regards, Bodo</description>
		<content:encoded><![CDATA[<p>Two comments:</p>
<p>1. Instead of</p>
<p>	OIFS=$IFS; IFS=$(echo -e &#8220;\n&#8221;); getopt $@; IFS=$OIFS</p>
<p>you could also just write</p>
<p>	getopt &#8220;$@&#8221;</p>
<p>2. It may be a security problem if the getopt function may write any variable in the normal namespace of the script. So, it&#8217;s better to prefix each variable by e.g. &#8220;arg_&#8221;. So &#8211;name bothie won&#8217;t get name=&#8221;bothie&#8221; but arg_name=&#8221;bothie&#8221;.</p>
<p>Regards, Bodo</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeremy Johnstone</title>
		<link>http://blog.apokalyptik.com/2008/07/07/command-line-arguments-in-bash-scripts/comment-page-1/#comment-7876</link>
		<dc:creator>Jeremy Johnstone</dc:creator>
		<pubDate>Tue, 22 Jul 2008 23:33:48 +0000</pubDate>
		<guid isPermaLink="false">http://blog.apokalyptik.com/?p=292#comment-7876</guid>
		<description>Bash has a built in function called getopts which does help with parsing command line arguement (help getopts for more info), but your solution seems to be a heck of a lot easier to use. 

Thanks for sharing!

-Jeremy</description>
		<content:encoded><![CDATA[<p>Bash has a built in function called getopts which does help with parsing command line arguement (help getopts for more info), but your solution seems to be a heck of a lot easier to use. </p>
<p>Thanks for sharing!</p>
<p>-Jeremy</p>
]]></content:encoded>
	</item>
</channel>
</rss>
