<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://www.wiki.mohid.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=193.136.136.173&amp;*</id>
		<title>MohidWiki - User contributions [en]</title>
		<link rel="self" type="application/atom+xml" href="http://www.wiki.mohid.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=193.136.136.173&amp;*"/>
		<link rel="alternate" type="text/html" href="http://www.wiki.mohid.com/index.php?title=Special:Contributions/193.136.136.173"/>
		<updated>2026-04-05T14:12:46Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.28.0</generator>

	<entry>
		<id>http://www.wiki.mohid.com/index.php?title=Bash&amp;diff=52</id>
		<title>Bash</title>
		<link rel="alternate" type="text/html" href="http://www.wiki.mohid.com/index.php?title=Bash&amp;diff=52"/>
				<updated>2008-08-01T12:42:03Z</updated>
		
		<summary type="html">&lt;p&gt;193.136.136.173: /* While */&lt;/p&gt;
&lt;hr /&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>