Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: export "a=b"=~



2017-03-08 15:44:28 +0000, Peter Stephenson:
[...]
> > Same behaviour in latest master.  This is because the MAGIC_EQUAL_SUBST
> > option, even when unset, implicitly applies to "export".  (The
> > declaration of "export" in builtins.c has the BINF_MAGICEQUALS flag
> > since before CVS.)
[...]
> So I think the following ought to work without any significant side
> effects.  I've renamed the controlling variable for clarity; the older,
> more general, name is now purely historical.
[...]

Some variations between shells:

$ ksh93 -c 'export a=~; echo $a; export "a"=~; echo $a; "export" a=~; echo $a; export a\=~; echo $a'
/home/chazelas
~
/home/chazelas
~
$ bash -c 'export a=~; echo $a; export "a"=~; echo $a; "export" a=~; echo $a; export a\=~; echo $a'
/home/chazelas
~
/home/chazelas
~
$ ARGV0=sh bash -c 'export a=~; echo $a; export "a"=~; echo $a; "export" a=~; echo $a; export a\=~; echo $a'
/home/chazelas
~
~
~
$ mksh -c 'export a=~; echo $a; export "a"=~; echo $a; "export" a=~; echo $a; export a\=~; echo $a'
/home/chazelas
/home/chazelas
/home/chazelas
~
$ dash -c 'export a=~; echo $a; export "a"=~; echo $a; "export" a=~; echo $a; export a\=~; echo $a'
~
~
~
~
$ yash -c 'export a=~; echo $a; export "a"=~; echo $a; "export" a=~; echo $a; export a\=~; echo $a'
~
~
~
~
$ zsh -c 'export a=~; echo $a; export "a"=~; echo $a; "export" a=~; echo $a; export a\=~; echo $a'
/home/chazelas
/home/chazelas
~
~
$ zsh -o magicequalsubst  -c 'export a=~; echo $a; export "a"=~; echo $a; "export" a=~; echo $a; export a\=~; echo $a'
/home/chazelas
/home/chazelas
/home/chazelas
~



After your patch:

$ ./Src/zsh -c 'export a=~; echo $a; export "a"=~; echo $a; "export" a=~; echo $a; export a\=~; echo $a'
/home/chazelas
~
~
~
$ ./Src/zsh -o magicequalsubst -c 'export a=~; echo $a; export "a"=~; echo $a; "export" a=~; echo $a; export a\=~; echo $a'
/home/chazelas
~
/home/chazelas
~


I can't say I have a strong opinion on what is best. I like
magic_equal_subst myself and I'm annoyed when ./configure
--prefix=~ doesn't work or sudo JAVA_HOME=~/jre... And I tend to
quote ~ when in doubt and don't want it to be expanded.

Note that in bash (when not in posix mode)

echo a=~

expands (so covers my sudo case above) but

echo --prefix=~

does not. What's on the left of the = has to look like a valid
literal unquoted bash variable name.

Started from:
https://askubuntu.com/questions/890415/why-couldnt-i-use-instead-of-home-username-when-giving-the-file-pat/890472#890472

-- 
Stephane



Messages sorted by: Reverse Date, Date, Thread, Author