Re: OT: spaces in pathnames
Re: OT: spaces in pathnames
- Subject: Re: OT: spaces in pathnames
- From: Daniel Azuelos <email@hidden>
- Date: Wed, 8 Jun 2005 15:35:40 +0200
Lawrence Paulson écrivait (wrote) :
| Can anybody point me to a tutorial on how to write shell scripts that
| work even if supplied pathnames contain spaces?
|
| Specifically, I have to pass an argument list from one program to
| another. It seems that I have to write the filenames to a file. Using
| ls -db, I can write the filenames with special characters fully
| escaped. The second program (invoked via open-x11) somehow needs to
| read these filenames. If I use $(<$FILENAME), the filenames get split
| at the spaces despite the backslashes, e.g. Isabelle\ app\ bundle
| becomes three words.
|
| Any thoughts? Some hack using IFS?
Any shell script having to deal with filenames which may contain
any legal character (like space, tab, backslash, accented characters...)
should only use the syntax:
"${var}"
(this syntax is the one in any Bourne style shell. There
exists the same evaluation inhibitor in any C style shell).
For a list of filenames passed as an argment to a shell script, the
correct syntax to use such a list is:
"$@"
Ex.:
$ bipbip () { for i in "$@" ; do echo "${i}" ; done ; }
$ bipbip 1 2 3
1
2
3
$ bipbip "1 2" 3
1 2
3
$ bipbip "1é2\ 3"
1é2\ 3
$
--
| R : Tu vois ! || daniel Azuelos - Institut Pasteur
| | Q : Tu crois ?
| | | R : Ça casse l'ordre chronologique de l'échange.
| | | | Q : En quoi répondre au dessus est-il gênant ?
_______________________________________________
Do not post admin requests to the list. They will be ignored.
X11-users mailing list (email@hidden)
This email sent to email@hidden