<?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: Bash Variable Tutorial &#8211; 6 Practical Bash Global and Local Variable Examples</title>
	<atom:link href="http://www.thegeekstuff.com/2010/05/bash-variables/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.thegeekstuff.com/2010/05/bash-variables/</link>
	<description>Guides, HowTos and Tips for Technology Geeks</description>
	<lastBuildDate>Thu, 09 Feb 2012 11:52:28 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: nix</title>
		<link>http://www.thegeekstuff.com/2010/05/bash-variables/comment-page-1/#comment-55874</link>
		<dc:creator>nix</dc:creator>
		<pubDate>Mon, 26 Jul 2010 00:46:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.thegeekstuff.com/?p=4200#comment-55874</guid>
		<description>Can you elaborate on this piece of code:
    var=$(cat file.txt)
How do i convert the above to an indexed array, list…?

The above reference is command substitution; it functions like using back ticks IE: 
`cat file.txt`.   

So the out put of the command is stored in the variable var.  

If you echo $var it will be one long line
If you echo &quot;$var&quot; it will appear as it does in the text file.

You can think of it as a one line array.  Array&#039;s can have an index or may not be indexed at all.  You can still loop through each element.  Might depend on the version of bash if it needs to be  quoted or not.  I forget how 2.x and 3.x worked... Sorry I am on version 4.x...

If you want an index; you have to create a counter variable.  As each line is read; you increment that counter.   There are various ways to populate an (indexed) array.  You can use the read command, process substitution and back ticks with a variable.  

Check out the BASH guides at the TLDP for various ways to  populate an array.</description>
		<content:encoded><![CDATA[<p>Can you elaborate on this piece of code:<br />
    var=$(cat file.txt)<br />
How do i convert the above to an indexed array, list…?</p>
<p>The above reference is command substitution; it functions like using back ticks IE:<br />
`cat file.txt`.   </p>
<p>So the out put of the command is stored in the variable var.  </p>
<p>If you echo $var it will be one long line<br />
If you echo &#8220;$var&#8221; it will appear as it does in the text file.</p>
<p>You can think of it as a one line array.  Array&#8217;s can have an index or may not be indexed at all.  You can still loop through each element.  Might depend on the version of bash if it needs to be  quoted or not.  I forget how 2.x and 3.x worked&#8230; Sorry I am on version 4.x&#8230;</p>
<p>If you want an index; you have to create a counter variable.  As each line is read; you increment that counter.   There are various ways to populate an (indexed) array.  You can use the read command, process substitution and back ticks with a variable.  </p>
<p>Check out the BASH guides at the TLDP for various ways to  populate an array.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: patolfo</title>
		<link>http://www.thegeekstuff.com/2010/05/bash-variables/comment-page-1/#comment-45814</link>
		<dc:creator>patolfo</dc:creator>
		<pubDate>Tue, 04 May 2010 16:22:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.thegeekstuff.com/?p=4200#comment-45814</guid>
		<description>Not at all, but i prefer cat command or l :)
By the way we are using bash 3 :(
so it is not possible, to use the -A array, i am not the admin either</description>
		<content:encoded><![CDATA[<p>Not at all, but i prefer cat command or l <img src='http://www.thegeekstuff.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
By the way we are using bash 3 <img src='http://www.thegeekstuff.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /><br />
so it is not possible, to use the -A array, i am not the admin either</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dj</title>
		<link>http://www.thegeekstuff.com/2010/05/bash-variables/comment-page-1/#comment-45805</link>
		<dc:creator>dj</dc:creator>
		<pubDate>Tue, 04 May 2010 14:55:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.thegeekstuff.com/?p=4200#comment-45805</guid>
		<description>Under Declaring a Bash Variable&quot;, you can add -A. Bash version 4 introduced associative arrays.

Have you seen anything to be gained, performance wise, when declaring a string that requires no substitution with single quotes vs double quotes.

LIST=&#039;/var/opt/bin/&#039;
vs.
LIST=&quot;/var/opt/bin/&quot;</description>
		<content:encoded><![CDATA[<p>Under Declaring a Bash Variable&#8221;, you can add -A. Bash version 4 introduced associative arrays.</p>
<p>Have you seen anything to be gained, performance wise, when declaring a string that requires no substitution with single quotes vs double quotes.</p>
<p>LIST=&#8217;/var/opt/bin/&#8217;<br />
vs.<br />
LIST=&#8221;/var/opt/bin/&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: patolfo</title>
		<link>http://www.thegeekstuff.com/2010/05/bash-variables/comment-page-1/#comment-45640</link>
		<dc:creator>patolfo</dc:creator>
		<pubDate>Mon, 03 May 2010 15:01:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.thegeekstuff.com/?p=4200#comment-45640</guid>
		<description>Can you elaborate on this piece of code:

var=$(cat file.txt)

How do i convert the above to an indexed array, list...?</description>
		<content:encoded><![CDATA[<p>Can you elaborate on this piece of code:</p>
<p>var=$(cat file.txt)</p>
<p>How do i convert the above to an indexed array, list&#8230;?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced
Content Delivery Network via Amazon Web Services: CloudFront: static.thegeekstuff.com

Served from: www.thegeekstuff.com @ 2012-02-09 10:13:13 -->
