ult/Section_5.rst
changeset 63 dc13f22e9489
parent 60 8a36825e21c5
child 91 6f2f2f949e32
equal deleted inserted replaced
62:780effcd7c5a 63:dc13f22e9489
   592     read variable
   592     read variable
   593     echo "Input - $variable"
   593     echo "Input - $variable"
   594   done
   594   done
   595   exit 0
   595   exit 0
   596 
   596 
   597 Now lets try and use these above mentioned options provided by shell to write a utility. Until now, when we try find or locate it looks through directories and files for result. But they wont search through tar archives and zipped files. Lets create a shell script for especially looking through these files: ::
   597 ``until``
       
   598 ~~~~~~~~~
       
   599 
       
   600 The ``until`` loop is similar to the ``while`` loop, except that it executes until the conditional command does not execute properly. 
       
   601 
       
   602 The infinite loop changes to the following, when ``until`` is used.
       
   603 ::
       
   604 
       
   605   until false
       
   606   do
       
   607     echo "True"
       
   608   done
       
   609 
       
   610 Now lets try and use these above mentioned options provided by shell to write a utility. Until now, when we try find or locate it looks through directories and files for result. But they wont search through tar archives and zipped files. Lets create a shell script for especially looking through these files
       
   611 ::
   598 
   612 
   599   #!/bin/sh
   613   #!/bin/sh
   600 
   614 
   601   #To check number of arguments being passed.
   615   #To check number of arguments being passed.
   602   if [ $# -eq 0 ] ; then
   616   if [ $# -eq 0 ] ; then
   626       echo "File present in $archive!" 
   640       echo "File present in $archive!" 
   627     fi  
   641     fi  
   628     done
   642     done
   629   done
   643   done
   630 
   644 
   631 ``until``
       
   632 ~~~~~~~~~
       
   633 
       
   634 The ``until`` loop is similar to the ``while`` loop, except that it executes until the conditional command does not execute properly. 
       
   635 
       
   636 The infinite loop changes to the following, when ``until`` is used.
       
   637 ::
       
   638 
       
   639   until false
       
   640   do
       
   641     echo "True"
       
   642   done
       
   643 
   645 
   644 Functions
   646 Functions
   645 ---------
   647 ---------
   646 
   648 
   647 When a group of commands are repeatedly being used within a script, it is convenient to group them as a function. This saves a lot of time and you can avoid retyping the code again and again. Also, it will help you maintain your code easily. Let's see how we can define a simple function, ``hello-world``. Functions can be defined in bash, either using the ``function`` built-in followed by the function name or just the function name followed by a pair of parentheses. 
   649 When a group of commands are repeatedly being used within a script, it is convenient to group them as a function. This saves a lot of time and you can avoid retyping the code again and again. Also, it will help you maintain your code easily. Let's see how we can define a simple function, ``hello-world``. Functions can be defined in bash, either using the ``function`` built-in followed by the function name or just the function name followed by a pair of parentheses. 
   697 	* http://www.freeos.com/guides/lsst/ 
   699 	* http://www.freeos.com/guides/lsst/ 
   698 	* http://bash.cyberciti.biz/guide/Main_Page
   700 	* http://bash.cyberciti.biz/guide/Main_Page
   699 	* http://tldp.org/LDP/abs/html/
   701 	* http://tldp.org/LDP/abs/html/
   700 	* http://tldp.org/LDP/Bash-Beginners-Guide/html/Bash-Beginners-Guide.html
   702 	* http://tldp.org/LDP/Bash-Beginners-Guide/html/Bash-Beginners-Guide.html
   701 	
   703 	
   702 
       
   703 ..  LocalWords:  allfiles txt cvf vf tf regex mkdir cp cd xvf gzip gz stdout