Friday, April 29, 2011

Play with Kornshell

Create test.ksh file

echo inout yes or no
read answer
case $answer in
   echo got a positive answer
   #the following ';;' is mandatory for every set
   #of comparative xxx) that you do
   echo got a 'no' ! ':('
   #assume the user wants to quit
   echo This is the default clause

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

>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
got a no ! :(

Reference :