<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://www.wiki.mohid.com/index.php?action=history&amp;feed=atom&amp;title=Bash</id>
		<title>Bash - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://www.wiki.mohid.com/index.php?action=history&amp;feed=atom&amp;title=Bash"/>
		<link rel="alternate" type="text/html" href="http://www.wiki.mohid.com/index.php?title=Bash&amp;action=history"/>
		<updated>2026-04-04T20:17:40Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.28.0</generator>

	<entry>
		<id>http://www.wiki.mohid.com/index.php?title=Bash&amp;diff=2940&amp;oldid=prev</id>
		<title>Guillaume: /* Manipulating variables */</title>
		<link rel="alternate" type="text/html" href="http://www.wiki.mohid.com/index.php?title=Bash&amp;diff=2940&amp;oldid=prev"/>
				<updated>2010-03-30T08:58:41Z</updated>
		
		<summary type="html">&lt;p&gt;‎&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Manipulating variables&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;tr style='vertical-align: top;' lang='en'&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 08:58, 30 March 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l96&quot; &gt;Line 96:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 96:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160; &amp;gt; let var = $othervar + 3&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160; &amp;gt; let var = $othervar + 3&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt; &amp;gt; ${var:3:2}&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;substring from 3-rd + 1 char with an offset of 2 char.&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt; &amp;gt; ${#var}&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;returns the number of chars in $var&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt; &amp;gt; ${var:0:${#var}-3}&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;substring everything except the last 3 chars&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt; &amp;gt; ${var:-3}&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;substring only the last 3 chars&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==External References==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==External References==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Guillaume</name></author>	</entry>

	<entry>
		<id>http://www.wiki.mohid.com/index.php?title=Bash&amp;diff=53&amp;oldid=prev</id>
		<title>Guillaume: 1 revision</title>
		<link rel="alternate" type="text/html" href="http://www.wiki.mohid.com/index.php?title=Bash&amp;diff=53&amp;oldid=prev"/>
				<updated>2008-12-03T10:26:56Z</updated>
		
		<summary type="html">&lt;p&gt;1 revision&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style='vertical-align: top;' lang='en'&gt;
				&lt;td colspan='1' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan='1' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 10:26, 3 December 2008&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan='2' style='text-align: center;' lang='en'&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Guillaume</name></author>	</entry>

	<entry>
		<id>http://www.wiki.mohid.com/index.php?title=Bash&amp;diff=52&amp;oldid=prev</id>
		<title>193.136.136.173: /* While */</title>
		<link rel="alternate" type="text/html" href="http://www.wiki.mohid.com/index.php?title=Bash&amp;diff=52&amp;oldid=prev"/>
				<updated>2008-08-01T12:42:03Z</updated>
		
		<summary type="html">&lt;p&gt;‎&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;While&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Configuring your environment variables: .bashrc==&lt;br /&gt;
&lt;br /&gt;
 &amp;gt; vim ~/.bashrc&lt;br /&gt;
 # .bashrc&lt;br /&gt;
 &lt;br /&gt;
 # Source global definitions&lt;br /&gt;
 if [ -f /etc/bashrc ]; then&lt;br /&gt;
     . /etc/bashrc&lt;br /&gt;
 fi&lt;br /&gt;
 &lt;br /&gt;
 # User specific aliases and functions&lt;br /&gt;
 export PATH=\&lt;br /&gt;
 ./bin:\&lt;br /&gt;
 /opt/local/bin:\&lt;br /&gt;
 /opt/local/gnu/bin:\&lt;br /&gt;
 /opt/local/gnome2/bin:\&lt;br /&gt;
 /opt/local/gnome1/bin:\&lt;br /&gt;
 /opt/local/mozilla/bin:\&lt;br /&gt;
 /usr/local/netcdf/include:\&lt;br /&gt;
 /usr/local/netcdf/lib:\&lt;br /&gt;
 /usr/local/netcdf/bin:\&lt;br /&gt;
 $PATH&lt;br /&gt;
 &lt;br /&gt;
 export MANPATH=\&lt;br /&gt;
 /opt/local/man:\&lt;br /&gt;
 /opt/local/gnu/man:\&lt;br /&gt;
 /opt/local/gnome2/man:\&lt;br /&gt;
 /opt/local/gnome1/man:\&lt;br /&gt;
 /opt/local/mozilla/man:\&lt;br /&gt;
 $MANPATH&lt;br /&gt;
 &lt;br /&gt;
==Flow control==&lt;br /&gt;
===While===&lt;br /&gt;
 Count=0&lt;br /&gt;
 while test $Count -lt 10&lt;br /&gt;
 do&lt;br /&gt;
 	echo &amp;quot;Inside first loop $Count&amp;quot;&lt;br /&gt;
	Count=`expr $Count + 1`&lt;br /&gt;
 done&lt;br /&gt;
 echo &amp;quot;Outside first loop $Count&amp;quot;&lt;br /&gt;
&lt;br /&gt;
===If===&lt;br /&gt;
 if [ $# -ne &amp;quot;$ARGS&amp;quot; ]; then&lt;br /&gt;
   echo &amp;quot;Description: Creates ring of tw bots&amp;quot;&lt;br /&gt;
   echo &amp;quot;Usage: &amp;gt; `basename $0` tw_ringof.txt&amp;quot;&lt;br /&gt;
   exit $E_BADARGS&lt;br /&gt;
 fi&lt;br /&gt;
&lt;br /&gt;
===Case===&lt;br /&gt;
 case &amp;quot;$3&amp;quot; in&lt;br /&gt;
   'test')&lt;br /&gt;
     twitbot=&amp;quot;pointptteste:pointpt&amp;quot;&lt;br /&gt;
     ;;&lt;br /&gt;
   *)&lt;br /&gt;
     twitbot=&amp;quot;weather${city}:weather&amp;quot;&lt;br /&gt;
     ;;&lt;br /&gt;
 esac&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
&lt;br /&gt;
===Find string in files===&lt;br /&gt;
Using the [[Find]] is good under windows when one whishes to search for a string inside a set of files. But in linux one must rely on alternative routes. This example uses '''for''', '''pipes''', '''grep''' and '''cat''' and prints out any line matching &amp;lt;code&amp;gt;MATCH&amp;lt;/code&amp;gt; from a list of files containing the &amp;lt;code&amp;gt;FILEPATTERN&amp;lt;/code&amp;gt; pattern:&lt;br /&gt;
 &amp;gt; for i in `find . | grep 'FILEPATTERN'`; do cat $i | grep MATCH;done&lt;br /&gt;
Now, if you want to change the &amp;lt;code&amp;gt;MATCH&amp;lt;/code&amp;gt; pattern with a &amp;lt;code&amp;gt;SUBST&amp;lt;/code&amp;gt; pattern, then check out [[Sed]].&lt;br /&gt;
&lt;br /&gt;
===Replicate directories tree===&lt;br /&gt;
In order to duplicate the directory tree simply type in bash inside the root of the directory to duplicate:&lt;br /&gt;
  &amp;gt; for i in `find . | grep '[^.]....$' | grep '[^.]...$' | grep '[^.]..$'`; do mkdir NEWROOT/$i; done&lt;br /&gt;
where ''NEWROOT'' is the new home directory of the duplicated directory tree.&lt;br /&gt;
&lt;br /&gt;
Here's a more elegant way of doing the directory skeleton replication:&lt;br /&gt;
 &amp;gt; for i in `find ROOT -type d | sed 's/ROOT/NEWROOT/g'`; do mkdir $i; done&lt;br /&gt;
&lt;br /&gt;
Now you are able to transfer files between the original directory tree and the duplicated directory tree. You can transfer them one file at a time, or by extensions:&lt;br /&gt;
 &amp;gt; for i in `find . | grep '\.SUFF$'`; do cp &lt;br /&gt;
where ''SUFF'' is the file extension. (Remember to execute the command from within the original directory tree's root.)&lt;br /&gt;
&lt;br /&gt;
===[[Piping]] output===&lt;br /&gt;
Here's one example that pipes the output of a program to the input of another program&lt;br /&gt;
 &amp;gt; echo My Sister | (read a b; echo $a; echo$b)&lt;br /&gt;
 My&lt;br /&gt;
 Sister&lt;br /&gt;
&lt;br /&gt;
Here's one example to mute the stdout and the stderr&lt;br /&gt;
 &amp;gt; echo coucou &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
&lt;br /&gt;
===Using if===&lt;br /&gt;
 &amp;gt; if [ `diff ${file}.txt ${file}.tmp | wc -l` -gt 0 ]; then echo Ok; fi&lt;br /&gt;
&lt;br /&gt;
===Reading and setting environment variables===&lt;br /&gt;
This examples creates the environment variable '''$mess''' by reading the line from file.txt:&lt;br /&gt;
 &amp;gt; read mess &amp;lt; file.txt&lt;br /&gt;
&lt;br /&gt;
===Manipulating variables===&lt;br /&gt;
 &amp;gt; ${var/pattern/replacement}&lt;br /&gt;
&lt;br /&gt;
 &amp;gt; let var = $othervar + 3&lt;br /&gt;
&lt;br /&gt;
==External References==&lt;br /&gt;
*[http://www.faqs.org/docs/bashman/bashref.html bash reference manual].&lt;br /&gt;
&lt;br /&gt;
[[Category:linux]]&lt;br /&gt;
[[Category:Script]]&lt;/div&gt;</summary>
		<author><name>193.136.136.173</name></author>	</entry>

	</feed>
<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
  ga('create', 'UA-56589921-5', 'auto');
  ga('send', 'pageview');
</script>