zsh-users
 help / color / mirror / code / Atom feed
* Passing parameters between noninteractive shells
@ 2006-10-25  8:31 Wojciech Pietron
  2006-10-25 10:45 ` Phil Pennock
  2006-10-25 14:42 ` Wayne Davison
  0 siblings, 2 replies; 5+ messages in thread
From: Wojciech Pietron @ 2006-10-25  8:31 UTC (permalink / raw)
  To: zsh-users

Hello,

I have access to two version of zsh: /bin/zsh (v. 3.0.6) and $HOME/bin/zsh
(v.4.0.2). /bin/zsh is my login prompt and I am unable to change it.

So I have the following section at the beginning of
my .zshenv:

===============.zshrc================
if [[ $ZSH_VERSION == 3.<->* ]]; then
     if [[ -x $HOME/bin/zsh && -o interactive ]]; then
        exec $HOME/bin/zsh
     else 
       if [[ -x $HOME/bin/zsh && ! -o interactive ]]; then
         exec $HOME/bin/zsh +o interactive
       fi
     fi
fi
#
# A lot of specific ZSH 4.0.2 commands:
# [...] 
===============.zshrc================

With a such a solution switching between v3.0.6 and 4.0.2 passes with no
problem in the interactive sessions.  

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.

Is there any way to pass parameters of non-interactive sessions to new
instance of zsh? I would also appreciate another workarounds of that
problem. Making the whole .zshrc compatible with 3.0.6 is out of the
question.

Thank you in advance
Wojciech Pietron


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Passing parameters between noninteractive shells
  2006-10-25  8:31 Passing parameters between noninteractive shells Wojciech Pietron
@ 2006-10-25 10:45 ` Phil Pennock
  2006-10-25 14:58   ` Bart Schaefer
  2006-10-25 14:42 ` Wayne Davison
  1 sibling, 1 reply; 5+ messages in thread
From: Phil Pennock @ 2006-10-25 10:45 UTC (permalink / raw)
  To: zsh-users

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Passing parameters between noninteractive shells
  2006-10-25  8:31 Passing parameters between noninteractive shells Wojciech Pietron
  2006-10-25 10:45 ` Phil Pennock
@ 2006-10-25 14:42 ` Wayne Davison
  1 sibling, 0 replies; 5+ messages in thread
From: Wayne Davison @ 2006-10-25 14:42 UTC (permalink / raw)
  To: zsh-users

On Wed, Oct 25, 2006 at 10:31:15AM +0200, Wojciech Pietron wrote:
> So I have the following section at the beginning of my .zshenv:

Is there a reason you aren't using .zlogin for this?  My .zlogin file
never gets read for non-interactive logins (since things like scp don't
start a login shell):

===============.zlogin================
[[ $ZSH_VERSION == 3.<->* ]] && exec $HOME/bin/zsh "$@"

The .zlogin file is sometimes not read in certain xterm situations, but
it doesn't sound like that will affect you.

..wayne..


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Passing parameters between noninteractive shells
  2006-10-25 10:45 ` Phil Pennock
@ 2006-10-25 14:58   ` Bart Schaefer
  2006-10-25 15:39     ` Peter Stephenson
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2006-10-25 14:58 UTC (permalink / raw)
  To: zsh-users

On Oct 25, 12:45pm, Phil Pennock wrote:
}
} exec $HOME/bin/zsh "$@"

I always use

    export SHELL=$HOME/bin/zsh
    exec $SHELL -$- "$@"

Options passed to the shell are not present in "$@", you have to get them
from "$-".  That does potentially miss a few, as there are not values in
$- for all possible setopts, but it preserves things like "-l" for a
login shell.

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

And, only in zsh and only with shwordsplit not set,

    $*  == "$@"

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

That statement is true for scripts that are meant to be portable among
various implementations of POSIX/Bourne-like shells.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Passing parameters between noninteractive shells
  2006-10-25 14:58   ` Bart Schaefer
@ 2006-10-25 15:39     ` Peter Stephenson
  0 siblings, 0 replies; 5+ messages in thread
From: Peter Stephenson @ 2006-10-25 15:39 UTC (permalink / raw)
  To: zsh-users

Bart Schaefer wrote:
> And, only in zsh and only with shwordsplit not set,
> 
>     $*  == "$@"

That's not quite true.  Elision of zero-length arguments is not
controlled by shwordsplit.

% set -- a '' c
% print -l $*
a
c
% print -l "$@"
a

c

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


To access the latest news from CSR copy this link into a web browser:  http://www.csr.com/email_sig.php


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2006-10-25 15:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-10-25  8:31 Passing parameters between noninteractive shells Wojciech Pietron
2006-10-25 10:45 ` Phil Pennock
2006-10-25 14:58   ` Bart Schaefer
2006-10-25 15:39     ` Peter Stephenson
2006-10-25 14:42 ` Wayne Davison

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).