Korn Shell Help Needed

How do I change directories to a path given by input variable in Korn Shell?

e.g. I tired with the Korn Shell below but it doesn't work.
----------------------------------
#!/bin/ksh
echo "Enter folder name: \c"
read folder
cd $folder
----------------------------------

Any help will be appreciated.

It depends on the way you invoke the script. I think you are invoking the script as ./steve.ksh

Look at this demo.

sh-2.05b$ cat steve.ksh 
#!/bin/ksh
echo -n "Enter folder name:"
read folder
cd $folder 
sh-2.05b$ pwd
/tmp
sh-2.05b$ ./steve.ksh 
Enter folder name:/tmp/steve
sh-2.05b$ pwd
/tmp
sh-2.05b$ . ./steve.ksh 
Enter folder name:/tmp/steve
sh-2.05b$ pwd
/tmp/steve
sh-2.05b$ 

One way is to invoke it as

. ./steve.ksh

I did reply, but Vinos is much more informative so I'll leave it to the pros.

Thank you vino and casphar!
I was invoking the script just by entering the name of the script (i.e. without "./" or ". ./").

I was trying to use this inside the code below (invoking it by . ./script.ksh)

#!/bin/ksh

echo "Enter folder name: \c"
read folder

#Remember current path to go back when loop finishes

pwd > current_path

#Start Loop

for file in `ls $folder`
do
      cd $folder
      mv $file new_$file
      cd | echo $current_path
done

rm current_path

... and it does modify the files in the given directory (folder_name) correctly however it gives the error below:

ksh: current_path: parameter not set
ksh: folder_name: not found
ksh: current_path: parameter not set
ksh: folder_name: not found
ksh: current_path: parameter not set
ksh: current_path: parameter not set
rm: current_path non-existent

Could someone tell me why I'm getting this error and how I can stop this error to appear?

Modifying your script...

#!/bin/ksh

echo "Enter folder name: \c"
read folder

#Remember current path to go back when loop finishes
current_path=$(pwd)

#Start Loop
cd $folder

for file in *
do
      mv $file new_$file
done

cd $current_path

That should work.

I dont understand what you are trying to do with the following:

rm current_path

Remove the directory or unset the variable ?

Thanks alot vino!

Regarding

rm current_path

I was trying to unset the variable.

cheers
Steve