Gene,
Using arguments with embedded spaces (like your file names)
is a particularly thorny problem in shell programming.
You have to be super diligent with double quoting
every dereferenced variable, and use "$@" as needed.
See below.
On 8/21/2009 11:53 PM, gene golub wrote:
Hi folks
I have a problem with files like: 'aaa bb (mail 4).txt'
When I try to use them in scripts as input files for db operations, I
am getting errors even if I put files in a double quotes:
\"$file1\"
I was thinking to copy them to other files while removing 'bad'
characters from their names, but I am still getting errors:
for k in *
do
F1=`echo $k|sed -e 's/[() ]//g'`
cp \"$k\" $F1
done
I get:
cp: target "aa_bb___mail_4_.sin.f1" must exist
Usage: cp [-acfimpPqrRSv] file1 [file2 ...] target
Any suggestions?
If the above is a renaming script whose args are files with 'bad chars'
to rename,
you're going to have to handle $k very carefully.
Below is my suggestion, which also replaces the sed with the ksh93
builtin variable substitution operation.
This will replace each space and parenthesis char with an underscore.
for k in "$@"
do
F1=${k//[() ]/_}
cp "$k" "$F1"
# F1=$(echo $k|sed -e 's/[() ]//g')
# cp \"$k\" $F1
done
# Sample invocation
#
myrename 'aaa bb (mail 4).txt' 'cc dd (foo).txt'
Regards,
Mario DeFazio
_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users