Difference between revisions of "BASH"

From RHS Wiki
Jump to navigation Jump to search
Line 36: Line 36:
 
=== Conditional ===
 
=== Conditional ===
 
==== if ====
 
==== if ====
 +
<source lang="bash">
 +
#!/bin/bash
 +
if [ "foo" = "foo" ]; then
 +
    echo expression evaluated as true
 +
else
 +
    echo expresion evaluated as false
 +
fi
 +
 +
#Condicional con variables
 +
#!/bin/bash
 +
T1="foo"
 +
T2="bar"
 +
if [ "$T1" = "$T2" ]; then
 +
    echo expresion evaluated as true
 +
else
 +
    echo expresion evaluated as false
 +
fi
 +
</source>
 +
 
==== case ====
 
==== case ====
 
=== User Input ===
 
=== User Input ===
 
=== Arrays ===
 
=== Arrays ===

Revision as of 00:53, 27 March 2015

BASH Script

Hello World

#!/bin/bash
STR="Hello World"
echo $STR

Variables

Local Variables

#!/bin/bash
HELLO=Hello 
function hello {
        local HELLO=World
        echo $HELLO
}
echo $HELLO
hello
echo $HELLO

Strings

Loops

While

#!/bin/bash
COUNTER=0
while [ $COUNTER -lt 10 ]; do
    echo The counter is $COUNTER
    let COUNTER=COUNTER+1
done

For

Conditional

if

#!/bin/bash
if [ "foo" = "foo" ]; then
    echo expression evaluated as true
else
    echo expresion evaluated as false
fi

#Condicional con variables
#!/bin/bash
T1="foo"
T2="bar"
if [ "$T1" = "$T2" ]; then
    echo expresion evaluated as true
else
    echo expresion evaluated as false
fi

case

User Input

Arrays