Showing posts with label shell. Show all posts
Showing posts with label shell. Show all posts

Friday, August 19, 2011

Wednesday, February 23, 2011

shell script - test

Check if the string is null
test -z $var && echo "The string is null" || echo "The string is not null"

Check if the var1 is greater than var2
test $var1 -gt $var2 && echo "var1 > var2" || echo "var1 < var2"

Check if value is 0
test $var -eq 0 && echo "var1 is 0" || echo "var1 is not 0"

Tuesday, February 22, 2011

shell script function

No parameter
function_name() {
    statement
}

call function
function_name



Parameter

function_name() {
    var=$1
    var2=$2
}

call function
function_name arg1 arg2





Return value (1)

function_name() {
    statement
    return 2
}

call function
echo "Return is: $?"





Return value (2)
function_name() {
    statement
    return $RET
}

call function
echo "Return is:
$RET"

Wednesday, January 12, 2011

count from file output

cat file | cut -f 1 | awk '{tot=tot+$1} END {print tot}'