cc: [email protected] 
Subject: Re: [ast-users] Files with unconventional names
--------

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?
>  


Using \"$file1\" is not putting the $file1 in double quotes.
Just use "$file1".  What you have done is added the double quotes
to thwe file name itself.

You can avoid file names being split even without double quotes,
if you disable IFS splitting by doing
        IFS=''
and if you disable file name generation with
        set -o noglob
However, in your case you need file name generation so

for k in *
do
        F1=$(print -r -- "$k" | sed -e 's/[() ]//g')
        cp "$k" "$F1"
done


David Korn
[email protected]
_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users

Reply via email to