July 2014
M T W T F S S
 123456
78910111213
14151617181920
21222324252627
28293031  

Categories

July 2014
M T W T F S S
 123456
78910111213
14151617181920
21222324252627
28293031  

korn shell (ksh) – for loop

Reading from a file

for line in $(cat /etc/passwd) do echo $line done

Iterate for a range

for number in {1..10} do echo “Current number is $number” done

Loop for values given

for planet in earth mars saturn jupiter do echo “The planet name is $planet” done

Loop for variable containing multiple values

planets=”earth mars […]

If statement and comparison operators

If statement without any brackets: These are used to check the outcome of a command. It return the exist status of command executed after if.

if grep -i oolala lyrics.txt then echo “lyrics.txt file contains oolala” else echo “lyrics.txt file doesn’t contain oolala” fi

if statement with []: These are used to check the […]

BASH – Default variables for a bash shell

$? => Return code of previous command $0 => Name of the script itself $1-9 => Argument number 1 to 9 given to script ${10} => Argument number 10 given to script $# => Total number of arguments given to script $@ => All arguments given to script but as an individual string values “$*” […]