Computing.Net > Forums > Unix > script copy filenames with brackets

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

script copy filenames with brackets

Reply to Message Icon

Name: matt
Date: October 3, 2003 at 11:22:52 Pacific
OS: mac os x
CPU/Ram: g4
Comment:

hey,

i am trying to write a bash script to backup recent files from a directory.

it works well, except that it does not copy files whose names have brackets.

(i.e. banner[1].jpg)

any advice on how i might be able to do this, or on code that would find and rename such files before i run my copy script?

thanks!

-matt


my script
____
#!/bin/sh

# this script will backup all files from the last month to a secondary location

date=$(date "+%m-%d-%y")
# mkdir backup_$date
cd /Volumes/192.168.1.15/apps/GoldMine/Mailbox/Attach/

find . -mtime 1 | \
while read file

do

#avoiding pesky trivial output
if [ "$file" = "." ]
then
else
echo "$file"
cp "$file" /Volumes/192.168.1.108/ScriptTest/backup_$date/"$file"
fi
done



Sponsored Link
Ads by Google

Response Number 1
Name: David Perry
Date: October 4, 2003 at 07:42:40 Pacific
Reply:

targetdir="/Volumes/192.168.1.108/ScriptTest/backup_${date}/"
for file in `find . -type f -mtime -1` ; do
cp $file $targetdir
done

See if you have a "rename command". Otherwise you could rename with sed.

file=`echo $file | sed -e 's/\[//' -e 's/\]//'`


0
Reply to Message Icon

Related Posts

See More


ksh script if then if? Setting Unix env



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: script copy filenames with brackets

copy files with pattern from a file www.computing.net/answers/unix/copy-files-with-pattern-from-a-file/6254.html

Simple script to copy files www.computing.net/answers/unix/simple-script-to-copy-files/4521.html

need help with unix script www.computing.net/answers/unix/need-help-with-unix-script/8209.html