Afficher un message
Vieux 21/08/2006, 04h29   #6
Jerry Fleming
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: how to escape special chars in filenames

Xicheng Jia wrote:
> Jerry Fleming wrote:
>> Chris F.A. Johnson wrote:
>>> On 2006-08-21, Jerry Fleming wrote:
>>>> I have a list (about 600) of files whose names contain special
>>>> characters, such as spaces, &, (. Under bash, they have to be escaped. I
>>>> was wondering if there is any command, or even a piece of sed, which can
>>>> be used to escape them.
>>> How are you using the names?
>>>
>>> The usual method is to quote the file name:
>>>
>>> for file in ./*
>>> do
>>> cat "$file"
>>> done
>>>

>> I am using the names with scp:
>>
>> scp special_file root@host:~/"special_file"
>>
>> Here I have to quote the destination special_file twice, one with double
>> quotes, one with escapes. Only double quotes won't work. I am wondering
>> how to escape special chars of filenames in a script.

>
> If you dont want to change the destination filename, then use 'dot' is
> enough, and no need to add ~/ to specify home directory(default).
>
> scp "$special_file" root@host:.
>
> But if the SRC of scp command isn't a shell variable, then using
> single-quotes is safer:
>
> scp 'special_file' root@host:.
>
> you can also use TAB auto-completion, shell can add proper backslashes
> for you.
>
> Xicheng
>

Thanks for all your . But I am using scp in a non-interactive
script, so auto-completion is no , and I do want the destination
filename to be different than the source. I have to escape the special
chars with backslashes. The problem is that I don't know where to insert
the backslashes in the filenames and where.
  Réponse avec citation
 
Page generated in 0,05655 seconds with 9 queries