|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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-- |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
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-- |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
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 |
|
![]() |
| Outils de la discussion | |
|
|