Korn shell

From s23
Jump to navigation Jump to search

Template loop detected: Template:Stub KSH is a Unix shell, it has scripting cabilities

Scripts

Here are some example of basic scripting commands

loops

Simple for loop

for x in  `ls .tar$` ; do  
echo "gzip $x"
# gzip $x
done



Simple while loop (infanitly repating)

while :
do
tail log.file
sleep 23
clear
done


If Else

Noarmal way

if [ -f /usr/bin/sudo ] ; then
        SUDO='/usr/bin/sudo'
else
        SUDO=
fi
echo $SUDO

Sneeky way

[ -f /usr/bin/sudo ] && SUDO='/usr/bin/sudo' || SUDO= ; echo $SUDO