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
----------------------------------
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?
#!/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: