Difference between revisions of "Bash examples"

From Teknologisk videncenter
Jump to: navigation, search
(Greetings)
Line 1: Line 1:
 
__TOC__
 
__TOC__
== if command ==
+
== bash builtins ==
=== Greetings ===
+
=== if command ===
 +
==== Greetings ====
 
<source lang="bash">
 
<source lang="bash">
 
#!/bin/bash
 
#!/bin/bash
Line 25: Line 26:
 
       fi
 
       fi
 
fi
 
fi
 +
</source>
 +
=== while ===
 +
==== count example ====
 +
<source lang="bash">
 +
#!/bin/bash
 +
COU=1
 +
while test $COU -lt 10000
 +
do
 +
  echo -en "COU = $COU\r"
 +
  COU=`expr $COU + 1`
 +
done
 
</source>
 
</source>

Revision as of 10:58, 12 February 2009

bash builtins

if command

Greetings

#!/bin/bash
#Uncomment HOUR=`date +%H` when using for real
#HOUR=`date +%H`
#
#HOUR=$1 only for testing purposes.....
HOUR=$1
if test $HOUR -le 7
  then
    echo "You are early go home"
  else if test $HOUR -le 8
         then
           echo "You are early"
         else if test $HOUR -lt 12
                then
                  echo "Good morning, Vietnam"
                else if test $HOUR -lt 16
                       then
                         echo "Good evening"
                     fi
              fi
       fi
fi

while

count example

#!/bin/bash
COU=1
while test $COU -lt 10000
do
  echo -en "COU = $COU\r"
  COU=`expr $COU + 1`
done