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

Re: Passing parameters between noninteractive shells



On 2006-10-25 at 10:31 +0200, Wojciech Pietron wrote:
> ===============.zshrc================
> if [[ $ZSH_VERSION == 3.<->* ]]; then
>      if [[ -x $HOME/bin/zsh && -o interactive ]]; then
>         exec $HOME/bin/zsh

exec $HOME/bin/zsh "$@"

>      else 
>        if [[ -x $HOME/bin/zsh && ! -o interactive ]]; then
>          exec $HOME/bin/zsh +o interactive

I'd think that this whole branch of the logic becomes unnecessary with
"$@", but if it is still needed then just put "$@" afterwards.

> The problem is with non-interactive sessions such as remote scp or cvs. This
> configuration makes such sessions hang because a new zsh is run and it does not
> know what it should do until I send 'exit' command. This is because the
> new shell is not given any parameters that had been passed to the
> previous instance of the shell - I believe so.

A shell script's parameters are available in $@ / $* and in zsh in
$argv.

With parameters:
 alpha
 foo bar
 wibble

then:
 "$*" == 'alpha foo bar wibble'
 "$@" == 'alpha' 'foo bar' 'wibble'

(ie, _most_ times that you see $* in a script it's a bug, normally "$@"
 is what's needed)

See zshparam(1), "POSITIONAL PARAMETERS" section.

Regards,
-Phil



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