<?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>Random Wisdom &#187; scripting</title>
	<atom:link href="http://scrolls.mafgani.net/tag/scripting/feed/" rel="self" type="application/rss+xml" />
	<link>http://scrolls.mafgani.net</link>
	<description>An attempt at organizing my thoughts ...</description>
	<lastBuildDate>Sun, 13 Mar 2011 22:54:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Create links with absolute paths in Linux</title>
		<link>http://scrolls.mafgani.net/2010/01/create-links-with-absolute-paths-in-linux/</link>
		<comments>http://scrolls.mafgani.net/2010/01/create-links-with-absolute-paths-in-linux/#comments</comments>
		<pubDate>Sat, 16 Jan 2010 19:10:18 +0000</pubDate>
		<dc:creator>Mostafa</dc:creator>
				<category><![CDATA[How To ...]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[console]]></category>
		<category><![CDATA[file processing]]></category>
		<category><![CDATA[filesystem]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://scrolls.mafgani.net/?p=420</guid>
		<description><![CDATA[The default behaviour of the linking command (ln) is a little strange under certain circumstances. Since it creates the links using the literal value of the target, symbolic links created using relative path structures can often fail. Consider the following: $ ln -s targetfile ../src/targetfile_link Without a doubt, &#8216;targetfile_link&#8217; will be a broken symlink since [...]]]></description>
			<content:encoded><![CDATA[<p>The default behaviour of the linking command (<strong>ln</strong>) is a little strange under certain circumstances. Since it creates the links using the literal value of the target, symbolic links created using relative path structures can often fail. Consider the following:</p>
<pre>$ ln -s targetfile ../src/targetfile_link</pre>
<p>Without a doubt, &#8216;targetfile_link&#8217; will be a broken symlink since it links to a target that it assumes is in the same directory:</p>
<pre>$ cd ../src &amp;&amp; ls -l targetfile_link
lrwxrwxrwx 1 mafgani mafgani 5 2010-01-16 18:19 targetfile_link -&gt; targetfile</pre>
<p>This is quite unfortunate since it clearly clashes with the way that the linking mechanism should work intuitively.</p>
<p>The solution is to force <strong>ln</strong> into automatically appending the absolute path to the target files. This can be achieved by using a simple shell script that acts as a wrapper for the real linking command:</p>
<pre style="color: #99ccff">
#!/bin/sh

# Step through the supplied arguments and append the absolute
# path to targets that exist
for ARG in $@
do
  if [ -e $ARG ]; then
    LNARGS="${LNARGS} ${PWD}/${ARG}";
  else
    LNARGS="${LNARGS} ${ARG}";
  fi
done

# Execute the actual link command with the modified args
exec /bin/ln ${LNARGS};
</pre>
<p>There are two known caveats:</p>
<ul>
<li> The link is &#8216;sub-optimal&#8217; if created from within the destination directory (the absolute path contains &#8216;../&#8217;s). It will still work however.</li>
<li>  The links will always be absolute. If that is undesirable, save the script as &#8216;absln&#8217; or something other than &#8216;ln&#8217;.</li>
</ul>
<p>Using &#8216;absln&#8217; instead of &#8216;ln&#8217; in the previously described scenario now produces a working symlink:</p>
<pre>$ absln -s targetfile ../src/targetfile_link
$ cd ../src/ &#038;&#038; ls -l targetfile_link
lrwxrwxrwx 1 mafgani mafgani 16 2010-01-16 19:13 targetfile_link -> /tmp/files/targetfile</pre>
]]></content:encoded>
			<wfw:commentRss>http://scrolls.mafgani.net/2010/01/create-links-with-absolute-paths-in-linux/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Bash scripting guides</title>
		<link>http://scrolls.mafgani.net/2005/12/bash-scripting-guides/</link>
		<comments>http://scrolls.mafgani.net/2005/12/bash-scripting-guides/#comments</comments>
		<pubDate>Fri, 30 Dec 2005 12:31:00 +0000</pubDate>
		<dc:creator>Mostafa</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[reference]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://scrolls.mafgani.net/?p=41</guid>
		<description><![CDATA[Here&#8217;s a modest list: http://www.tldp.org/LDP/Bash-Beginners-Guide/html/http://www.opengroup.org/onlinepubs/009695399/toc.htmhttp://cfaj.freeshell.org/shell/http://www.shelldorado.com/http://home.comcast.net/~j.p.h/cus-faq.htmlhttp://sed.sourceforge.net/sed1line.txthttp://www.student.northpark.edu/pemente/sed/sedfaq.htmlhttp://www.faqs.org/faqs/unix-faq/faq/part1/http://www.shelldorado.com/goodcoding/cmdargs.htmlhttp://www.macobserver.com/tips/macosxcl101/http://www.wagoneers.com/UNIX/FIND/find-usage.htmlhttp://cnswww.cns.cwru.edu/~chet/bash/bashref.htmlhttp://www.tldp.org/LDP/abs/html/ Got the links from a post by Charles Howse on the 30th of December 2005 to the thread Why questions don&#8217;t get answered, or &#8220;No, I&#8217;ve already RTFM, tell me the answer!&#8221; on fedora-list.]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a modest list:</p>
<p><a href="http://www.tldp.org/LDP/Bash-Beginners-Guide/html/">http://www.tldp.org/LDP/Bash-Beginners-Guide/html/</a><br /><a href="http://www.opengroup.org/onlinepubs/009695399/toc.htm">http://www.opengroup.org/onlinepubs/009695399/toc.htm</a><br /><a href="http://cfaj.freeshell.org/shell/">http://cfaj.freeshell.org/shell/</a><br /><a href="http://www.shelldorado.com/">http://www.shelldorado.com/</a><br /><a href="http://home.comcast.net/~j.p.h/cus-faq.html">http://home.comcast.net/~j.p.h/cus-faq.html</a><br /><a href="http://sed.sourceforge.net/sed1line.txt">http://sed.sourceforge.net/sed1line.txt</a><br /><a href="http://www.student.northpark.edu/pemente/sed/sedfaq.html">http://www.student.northpark.edu/pemente/sed/sedfaq.html</a><br /><a href="http://www.faqs.org/faqs/unix-faq/faq/part1/">http://www.faqs.org/faqs/unix-faq/faq/part1/</a><br /><a href="http://www.shelldorado.com/goodcoding/cmdargs.html">http://www.shelldorado.com/goodcoding/cmdargs.html</a><br /><a href="http://www.macobserver.com/tips/macosxcl101/">http://www.macobserver.com/tips/macosxcl101/</a><br /><a href="http://www.wagoneers.com/UNIX/FIND/find-usage.html">http://www.wagoneers.com/UNIX/FIND/find-usage.html</a><br /><a href="http://cnswww.cns.cwru.edu/~chet/bash/bashref.html">http://cnswww.cns.cwru.edu/~chet/bash/bashref.html</a><br /><a href="http://www.tldp.org/LDP/abs/html/">http://www.tldp.org/LDP/abs/html/</a></p>
<p>Got the links from a post by <span style="font-weight:bold;">Charles Howse</span> on the 30th of December 2005 to the thread <span style="font-style:italic;">Why questions don&#8217;t get answered, or &#8220;No, I&#8217;ve already RTFM, tell me the answer!&#8221;</span> on <a href="https://www.redhat.com/archives/fedora-list/">fedora-list</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://scrolls.mafgani.net/2005/12/bash-scripting-guides/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Command line search utility</title>
		<link>http://scrolls.mafgani.net/2005/12/command-line-search-utility/</link>
		<comments>http://scrolls.mafgani.net/2005/12/command-line-search-utility/#comments</comments>
		<pubDate>Tue, 27 Dec 2005 11:34:00 +0000</pubDate>
		<dc:creator>Mostafa</dc:creator>
				<category><![CDATA[How To ...]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[search]]></category>

		<guid isPermaLink="false">http://scrolls.mafgani.net/?p=40</guid>
		<description><![CDATA[While studying for one of the finals this year, I felt the need for a CLI search utility that would search on Google, Wikipedia, Google Images, etc. I didn&#8217;t know of any tools that would already do this so I decided to write my own little bash script: #!/bin/bash #Needs the htmlview package opt="$1" str="$2" [...]]]></description>
			<content:encoded><![CDATA[<p>While studying for one of the finals this year, I felt the need for a CLI search utility that would search on Google, Wikipedia, Google Images, etc. I didn&#8217;t know of any tools that would already do this so I decided to write my own little bash script:</p>
<pre>
#!/bin/bash
#Needs the htmlview package

opt="$1"
str="$2"

#Create the search string
until [ -z "$3" ]
do
  str="$str+$3"
  shift
done

case "$opt" in
    "google"  )
    htmlview http://www.google.com/search?hl=en\&#038;q="$str"&#038;btnG=Google+Search &#038;
    ;;

    "image"   )
    htmlview http://images.google.com/images?q="$str"\&#038;safe=off &#038;
    ;;

    "wpedia"  )
    htmlview http://en.wikipedia.org/wiki/Special:Search?search="$str" &#038;
    ;;

    "scholar" )
    htmlview http://scholar.google.com/scholar?q="$str"\&#038;ie=UTF-8\&#038;oe=UTF-8\&#038;hl=en\&#038;btnG=Search &#038;
    ;;

    "ieee"    )
    htmlview http://ieeexplore.ieee.org/search/searchresult.jsp?queryText=\%28\%28"$str"\%29\%3Cin\%3Emetadata\%29 &#038;
    ;;

    *         )
    echo "Usage: search engine searchterm [searchterms]"
    echo
    echo "Engines: google    Basic Google websearch"
    echo "         image     Unfiltered Google image search"
    echo "         wpedia    Wikipedia (English)"
    echo "         scholar   Google Scholar"
    echo "         ieee      IEEE Xplore (needs subscription)"
    echo
    echo "Example: search image batman"
    ;;
esac

echo

exit 0
</pre>
<p>It makes use of the <span style="font-weight:bold;">htmlview</span> package to discover the default browser and display the results. The use of the script is quite straightforward:</p>
<p><PRE>
[darkknight@darkworld bin]$ search image batman begins

</pre></p>
<p>As is, it considers all search terms. Fancy things like Boolean expressions are not supported (yet <img src='http://scrolls.mafgani.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ). A copy of the script can be found <a href="http://pandora.iu-bremen.de/~mafgani/stuff/search">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://scrolls.mafgani.net/2005/12/command-line-search-utility/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

