If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > This script doesn't work when a folder name is containing a space

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-11-04, 23:50
freelancers freelancers is offline
Registered User
 
Join Date: Jul 2004
Posts: 5
Question This script doesn't work when a folder name is containing a space

Hi friends,

I'm using this script to compress a folder in a directory. I found that script only suitable for a folder name which not containing space (eg freelancers). But it won't work if this folder name is containing a space (free lancers). I would like to make this script more flexible, no matter what kind of folder name, it also work. So do you all have any idea? Thank you!!



for folder in *
do
# Compress any folder found in the directories
if [ -d $folder ]
then
tar zcvf $folder.tgz $folder
rm -r $folder
else
echo “No folder was found,program is exiting..................”
fi
done
Reply With Quote
  #2 (permalink)  
Old 08-12-04, 09:35
chrisgu chrisgu is offline
Registered User
 
Join Date: Aug 2004
Posts: 2
>> if [ -d "$folder" ]
>> then
>> tar zcvf "$folder".tgz "$folder"
>> rm -r "$folder"
>> else
>> echo “No folder was found,program is exiting..................”
>> fi
>> done

If you put quotes round the variable folder you should be able to handle any directory name.

Chris.

Last edited by chrisgu; 08-12-04 at 09:49.
Reply With Quote
  #3 (permalink)  
Old 08-16-04, 23:44
freelancers freelancers is offline
Registered User
 
Join Date: Jul 2004
Posts: 5
Smile Thanks,Chris

Thanks Chris you are the man..the script that you teach is working well. Thanks a lot!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On