<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Open Sourcery &#187; scripting</title>
	<atom:link href="http://www.opensourcery.co.uk/tag/scripting/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.opensourcery.co.uk</link>
	<description>Open Source Support and Consultancy</description>
	<lastBuildDate>Wed, 27 Aug 2008 12:45:47 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Automatically backing up files before making changes</title>
		<link>http://www.opensourcery.co.uk/2008/06/backing-up-files-before-making-changes/</link>
		<comments>http://www.opensourcery.co.uk/2008/06/backing-up-files-before-making-changes/#comments</comments>
		<pubDate>Sun, 01 Jun 2008 08:40:01 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[BASH scripting]]></category>
		<category><![CDATA[System Administration]]></category>
		<category><![CDATA[Tips and tricks]]></category>
		<category><![CDATA[backups]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[best practice]]></category>
		<category><![CDATA[change control]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://www.opensourcery.co.uk/?p=43</guid>
		<description><![CDATA[It&#8217;s best practice (and common sense) to make a backup of a file before you edit it. Unfortunately it&#8217;s easy to forget to do this. We use this simple script below to make a time/date stamped copy of a file before launching the editor (in this case vim). We create it as /usr/local/bin/bvi.

#!/bin/bash
[[ -r $1 [...]<p>a</p>
]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s best practice (and common sense) to make a backup of a file before you edit it. Unfortunately it&#8217;s easy to forget to do this. We use this simple script below to make a time/date stamped copy of a file before launching the editor (in this case <a href="http://www.vim.org/" target="_blank">vim</a>). We create it as <em>/usr/local/bin/bvi</em>.</p>
<blockquote><p><code><br />
#!/bin/bash<br />
[[ -r $1 ]] &#038;&#038; cp $1{,.`date +%Y%m%d-%H%M`} ||  echo "$1 is a new file"</code><br />
vim $1
</p></blockquote>
<p>We then add the following two aliases to our ~/.bashrc file to make sure it&#8217;s run automatically when we call vim.</p>
<blockquote><p><code>alias vi=/usr/local/bin/bvi<br />
alias vim=/usr/local/bin/bvi<br />
</code></p></blockquote>
<p>This isn&#8217;t a replacement for good version control of important files, but it&#8217;s a good safety net. It&#8217;s also worth noting that this can leave a lot of old copies of files laying about, so it&#8217;s work cleaning out old copies every now and again.</p>
<p>a</p>
]]></content:encoded>
			<wfw:commentRss>http://www.opensourcery.co.uk/2008/06/backing-up-files-before-making-changes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Parsing parameters in a BASH shell script</title>
		<link>http://www.opensourcery.co.uk/2008/04/parsing-parameters-bash-shell-script/</link>
		<comments>http://www.opensourcery.co.uk/2008/04/parsing-parameters-bash-shell-script/#comments</comments>
		<pubDate>Mon, 07 Apr 2008 13:19:57 +0000</pubDate>
		<dc:creator>dave</dc:creator>
				<category><![CDATA[BASH scripting]]></category>
		<category><![CDATA[Tips and tricks]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[tip]]></category>

		<guid isPermaLink="false">http://www.opensourcery.co.uk/?p=40</guid>
		<description><![CDATA[This is a simple alternative to using getopts to parse parameters in a BASH shell script which makes use of the powerful parameter substitution functions in BASH. It should be sufficient for most scripts:

until [[ ! "$*" ]]; do
&#160;&#160;if [[ ${1:0:2} = '--' ]]; then
&#160;&#160;&#160;&#160;PAIR=${1:2}
&#160;&#160;&#160;&#160;PARAMETER=`echo ${PAIR%=*} &#124; tr [:lower:] [:upper:]`
&#160;&#160;&#160;&#160;eval P_$PARAMETER=${PAIR##*=}
&#160;&#160;fi
&#160;&#160;shift
done


The script processes parameters in [...]<p>a</p>
]]></description>
			<content:encoded><![CDATA[<p>This is a simple alternative to using getopts to parse parameters in a BASH shell script which makes use of the powerful parameter substitution functions in BASH. It should be sufficient for most scripts:</p>
<blockquote><p><code><br />
until [[ ! "$*" ]]; do<br />
&nbsp;&nbsp;if [[ ${1:0:2} = '--' ]]; then<br />
&nbsp;&nbsp;&nbsp;&nbsp;PAIR=${1:2}<br />
&nbsp;&nbsp;&nbsp;&nbsp;PARAMETER=`echo ${PAIR%=*} | tr [:lower:] [:upper:]`<br />
&nbsp;&nbsp;&nbsp;&nbsp;eval P_$PARAMETER=${PAIR##*=}<br />
&nbsp;&nbsp;fi<br />
&nbsp;&nbsp;shift<br />
done<br />
</code>
</p></blockquote>
<p>The script processes parameters in the format <code>--<em>name</em>=<em>value</em></code> or <code>--<em>flag</em></code>.</p>
<p>So, executing: <code>./example.sh --number=123 --show</code></p>
<p>Will result in the variable $P_NUMBER being set to &#8220;123&#8243; and the variable $P_SHOW evaluating to true as it is set, albeit to a empty value.</p>
<p>a</p>
]]></content:encoded>
			<wfw:commentRss>http://www.opensourcery.co.uk/2008/04/parsing-parameters-bash-shell-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
