Korn Shell Code Reference
#!/bin/ksh #korn shell executable path
# #single line comment
##Printing Output:
echo "hello, how are you?" #prints what's in quote
echo -e "hello, how are you\n" #prints with a new line
echo -e "\hello, how are you?" #prints with a tab
print #prints new line
print "hello, how are you?" #prints quote
##Variable Assignment:
x=4 #variable assignment number
y=34 #variable assignment number
total="" #variable assignment empty
status="out of office" #variable assignment string
myls=`ls -lrt` #assigning linux command to a variable
echo $x #printing value of x
echo "the value of y is $y" #printing
echo "today, Joe is $status" #printing
echo $myls #printing the output of ls -lrt
##Debugging:
set -x #enable debugging mode
set +x #disabling debugging mode
#!/bin/ksh -x #debugging enabled for whole program
echo $? #printing program exit location
##Read:
echo -e "\nExample 1:" #printing from quote
echo "What is your name? " #printing from quote
read name #read user input and assign to a name variable
echo -e "Nice name $name" #printing user input
echo -e "\nExample 2:" #printing from quote
echo "What is your full name?" #asking name
read first middle last #assign user input to first,middle and last
echo "Your full name is $first $middle $last" #print full name
echo -e "\nExample 3" #printing from quote
print -n "Where do you work?" #ask question -n will no let the carriage return
read workplace #read user input and assign to variable
echo "do you like $workplace" #printing user input
No comments