Friday, April 29, 2011

Play with Kornshell

Create test.ksh file


#!/bin/ksh
echo inout yes or no
read answer
case $answer in
 yes|Yes|y)
   echo got a positive answer
   #the following ';;' is mandatory for every set
   #of comparative xxx) that you do
   ;;
 no)
   echo got a 'no' ! ':('
   ;;
 q*|Q*)
   #assume the user wants to quit
   exit
   ;;
 *)
   echo This is the default clause
   ;;
esac

Make sure you write #!/bin/ksh at the top  of your file

I use this to give permission

> chmod 0755 test.ksh

Run the file

>./test.ksh
>ksh: ./test.ksh:  not found  <-- upps I got this error

So I try use this command
>ksh test.ksh
>test.ksh[2]: ^M:  not found  <--- upp this error meaning something to do with space


Use dos2unix,
>dos2unix -437 test.ksh test1.ksh
>dos2unix -437 test1.ksh test.ksh  

-437 is use to avoid this error
could not open /dev/kbd to get keyboard type US keyboard assumed
could not get keyboard type US keyboard assumed

After this maybe you can delete test1.ksh.I am not sure how to dos2unix using only one file, will dig it out later

>chmod 0755 test.ksh
>./test.ksh      <---- I can use this command back instead of   > ksh test.ksh

Yey!! The output something like below, of course depend on your input

inout yes or no
no
got a no ! :(



Reference : http://www.bolthole.com/solaris/ksh.html