Showing posts with label ksh tutorials. Show all posts
Showing posts with label ksh tutorials. Show all posts

Ksh Tutorials :if else Branching

Ksh Tutorials :if else Branching
if then fi
if [[ $value -eq 7 ]];then
print "$value is 7"
fi
or:
if [[ $value -eq 7 ]]
then
print "$value is 7"
fi
or:
if [[ $value -eq 7 ]];then print "$value is 7";fi
if then else fi
if [[ $name = "John" ]];then
print "Your welcome, ${name}."
else
print "Good bye, ${name}!"
fi
if then elif then else fi
if [[ $name = "John" ]];then
print "Your welcome, ${name}."
elif [[ $name = "Hanna" ]];then
print "Hello, ${name}, who are you?"
else
print "Good bye, ${name}!"
fi
Case esac
case $var in
john
fred) print $invitation;;
martin) print $declination;;
*) print "Wrong name...";;
esac

Ksh Tutorials :Declaring Variables

Ksh Tutorials :Declaring Variables
Filling in
When filling into a variable then one uses just it's name: state="US" and no blanks. There is no difference between strings and numbers: price=50.
Using
When using a variable one needs to put a $ sign in front of it: print $state $price.
Arrays
Set and use an array like:
arrname[1]=4 To fill in
print ${arraname[1]} To print out
${arrname[*]} Get all elements
${#arrname[*]} Get the number of elements
Declaration
There are happily no declarations of variables needed in ksh. One cannot have decimals only integers.