![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Help needed in character replacement in Korn Shell | stevefox | Shell Programming and Scripting | 8 | 03-30-2007 12:59 AM |
| bourne shell or korn shell? | XZOR | UNIX for Dummies Questions & Answers | 2 | 10-06-2006 03:34 AM |
| how to convert from korn shell to normal shell with this code? | forevercalz | Shell Programming and Scripting | 21 | 11-23-2005 02:18 AM |
| KORN Shell - Spawn new shell with commands | frustrated1 | Shell Programming and Scripting | 2 | 04-20-2005 03:23 PM |
| Korn Shell | gpanesar | Shell Programming and Scripting | 4 | 03-25-2005 05:46 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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. |
|
||||
|
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) Code:
#!/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... Code:
#!/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: Code:
rm current_path Remove the directory or unset the variable ? |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|