PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > quoting pathnames with spaces
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

quoting pathnames with spaces

Réponse
 
LinkBack Outils de la discussion
Vieux 21/08/2006, 02h38   #1
Charles Russell
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut quoting pathnames with spaces

Is there some way to define macro WPATH so that I can just type cp file
$WPATH and not have to type the quotes, cp file "$WPATH", every time?
(I'm using cygwin and have to contend with Windows pathnames.) If
possible, the same macro should be usable in Bourne shell scripts as
well as at the command line.
  Réponse avec citation
Vieux 21/08/2006, 13h41   #2
Michal Nazarewicz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: quoting pathnames with spaces

Charles Russell <SPAMworFREEwor@bellsouth.net> writes:

> Is there some way to define macro WPATH so that I can just type cp
> file $WPATH and not have to type the quotes, cp file "$WPATH", every
> time?


It would be definitly more complicated then typing cp file "$WPATH".

--
Best regards, _ _
.o. | Liege of Serenly Enlightened Majesty of o' \,=./ `o
..o | Computer Science, Michal "mina86" Nazarewicz (o o)
ooo +--<mina86*tlen.pl>--<jid:mina86*jabber.org>--ooO--(_)--Ooo--
  Réponse avec citation
Vieux 21/08/2006, 15h46   #3
Charles Russell
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: quoting pathnames with spaces

Michal Nazarewicz wrote:
> Charles Russell <SPAMworFREEwor@bellsouth.net> writes:
>
>
>>Is there some way to define macro WPATH so that I can just type cp
>>file $WPATH and not have to type the quotes, cp file "$WPATH", every
>>time?

>
>
> It would be definitly more complicated then typing cp file "$WPATH".
>

But I would only have to do it once. And I could use it as a prototype
the next time I had the problem.
  Réponse avec citation
Vieux 21/08/2006, 17h08   #4
Michal Nazarewicz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: quoting pathnames with spaces

Charles Russell <SPAMworFREEwor@bellsouth.net> writes:

> Michal Nazarewicz wrote:
>> It would be definitly more complicated then typing cp file "$WPATH".
>>

> But I would only have to do it once. And I could use it as
> a prototype the next time I had the problem.


You'll have to write something like:

cp file $(escape $VARIABLE)

anyways and still I dunno if that would work. Or you'll have to create
houndreads of functions like:

cp_FOO () { cp -- "$1" "$FOO"; }
mv_FOO () { mv -- "$1" "$FOO"; }
cp_BAR () { cp -- "$1" "$BAR"; }
mv_BAR () { mv -- "$1" "$BAR"; }
something_baz () { something -- "$1" "$BAZ"; }

I don't think it's worth it.

--
Best regards, _ _
.o. | Liege of Serenly Enlightened Majesty of o' \,=./ `o
..o | Computer Science, Michal "mina86" Nazarewicz (o o)
ooo +--<mina86*tlen.pl>--<jid:mina86*jabber.org>--ooO--(_)--Ooo--
  Réponse avec citation
Vieux 21/08/2006, 18h50   #5
Stephane Chazelas
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: quoting pathnames with spaces

On Sun, 20 Aug 2006 20:38:28 -0500, Charles Russell wrote:
> Is there some way to define macro WPATH so that I can just type cp file
> $WPATH and not have to type the quotes, cp file "$WPATH", every time?
> (I'm using cygwin and have to contend with Windows pathnames.) If
> possible, the same macro should be usable in Bourne shell scripts as
> well as at the command line.


Use zsh, then you don't need the quotes (except for the case
where $WPATH may be empty in which case zsh does expand it to no
argument instead of an empty argument).

And if you want either of the other behaviors other shell have
by default upon variable expansion, use:

cmd $=var

To ask that word splitting be performed upon the expansion

cmd $~var

to ask for filename genration (wildcards in $var to be
expanded).

cmd $=~var

combines both and is equivalent to

cmd $var

in other shells.

In other shells, you can do

IFS=
set -f

And you can then use variable expansion as in zsh. But note that
then command substitutions are not word split either and there's
no $=var nor $~var in other shells.

In any case, in zsh and with other shells with IFS=;set -f, in
scripts, it's still better to quote variable expansion (for the
expansion of empty variables to start with).

--
Stephane
  Réponse avec citation
Vieux 22/08/2006, 00h57   #6
Charles Russell
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: quoting pathnames with spaces

Michal Nazarewicz wrote:
> Charles Russell <SPAMworFREEwor@bellsouth.net> writes:
>
>
>>Michal Nazarewicz wrote:
>>
>>>It would be definitly more complicated then typing cp file "$WPATH".
>>>

>>
>>But I would only have to do it once. And I could use it as
>>a prototype the next time I had the problem.

>
>
> You'll have to write something like:
>
> cp file $(escape $VARIABLE)
>
> anyways and still I dunno if that would work. Or you'll have to create
> houndreads of functions like:
>
> cp_FOO () { cp -- "$1" "$FOO"; }
> mv_FOO () { mv -- "$1" "$FOO"; }
> cp_BAR () { cp -- "$1" "$BAR"; }
> mv_BAR () { mv -- "$1" "$BAR"; }
> something_baz () { something -- "$1" "$BAZ"; }
>
> I don't think it's worth it.
>

The standard Bourne shell often has simple tricks that are not apparent
to me, but in this case, I suppose there is no way to write a macro that
expands to a quoted string. If you double quote or escape in any way,
it won't expand at all.
  Réponse avec citation
Vieux 22/08/2006, 09h19   #7
Stephane Chazelas
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: quoting pathnames with spaces

On Sun, 20 Aug 2006 20:38:28 -0500, Charles Russell wrote:
> Is there some way to define macro WPATH so that I can just type cp file
> $WPATH and not have to type the quotes, cp file "$WPATH", every time?
> (I'm using cygwin and have to contend with Windows pathnames.) If
> possible, the same macro should be usable in Bourne shell scripts as
> well as at the command line.


You could define

r() {
c=1 cmd=
for i do
case $i in
£*) cmd="$cmd \"\${${i#£}}\"";;
*) cmd="$cmd \"\${$c}\"";;
esac
c=$(($c + 1))
done
eval "$cmd"
}

then:

r cp file £WPATH


--
Stephane
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 19h17.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,12017 seconds with 15 queries