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

Re: problem redeclaring path variable (ksh incompatibility)



On Mar 18,  8:42am, Michael Wardle wrote:
} Subject: Re: problem redeclaring path variable (ksh incompatibility)
}
} > Try running your test script with ARGV0=sh in the environment and note
} > the difference in behavior.
} 
} It didn't appear to make any difference.

Er, I was assuming, because you were posting to a zsh mailing list, that
your usual shell was zsh, which is possibly a bad assumption.  That is,
ARGV0 is magic to zsh -- not to the new zsh being started up, but to the
currently running zsh that is printing your PS1 prompt.  If your login
shell is bash or ksh, the ARGV0=sh isn't going to make any difference.

So, first start an interactive zsh, and then from the prompt of that,
run "ARGV0=sh zsh -p yourtestscript", and NOT "ARGV0=sh yourtestscript".

Or, do "ln -s `which zsh` /tmp/sh" and then "/tmp/sh -p yourtestscript".

} Are you sure this hides $path

It causes it never to become set in the first place.

} or are you just suggesting this should be the normal way to invoke zsh 
} any time I want it to conform closely to POSIX shell?

If you want zsh to conform closely to the POSIX shell you have to make a
link to it whose pathname ends in "sh" (actually any string starting with
the letter "s" other than "su" will work) and run it via that link.  The
trick with ARGV0 is a zsh-ism that simulates having done so.

} So this works:
} typeset path
} path=
} path="scalar"

This declares a local path, but it inherits the special features of the
global path.  It then makes it empty (redundant), and finally makes it
a single-element array.

} But this doesn't:
} typeset path=
} path="scalar"

It doesn't work because "typeset path=" fails *entirely* when it prints
the "can't assign initial value" error message; consequently you have
not succeeded in declaring "path" to be local, and the assigment affects
the global.

} And neither does this:
} typeset path=""
} path="scalar"

Same problem.

} > zsh% func() { emulate ksh; typeset path ; path=scalar ; typeset path }
} > zsh% func
} > path=(scalar)
} 
} Assuming a -m flag to the final typeset, this certainly verifies what 
} you said.

Right, I forgot the -m is required in 4.2.  I tried it in 4.0, in which
older version "emulate ksh" does not imply "setopt TYPESET_SILENT".



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