|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Unix Script cannot copy filename with brackets
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 |
|
#2
|
|||
|
|||
|
solved my own problem using the tr command
# 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 # file2 holds the filename without brackets echo "$file" > temp.txt file2=$(tr -d [] < temp.txt) #remove bracket characters in target so copy operation will not fail if [ "$file" != "$file2" ] then cp "$file" /Volumes/192.168.1.108/ScriptTest/backup_$date/"$file2" #do nothing to the directory you are in elif [ "$file" = "." ] then echo backup started on `date` #copy an entire directory elif [ -d "$file" ] then cp -r "$file" /Volumes/192.168.1.108/ScriptTest/backup_$date/"$file" else cp "$file" /Volumes/192.168.1.108/ScriptTest/backup_$date/"$file" fi done |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Unix Script cannot copy filename with brackets |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|