zsh-workers
 help / color / mirror / code / Atom feed
From: Dave Yost <Dave@Yost.com>
To: zsh-workers@sunsite.dk
Cc: bob@proulx.com (Bob Proulx)
Subject: exec -l
Date: Sun, 29 Apr 2007 17:52:48 -0700	[thread overview]
Message-ID: <pdy98830624081fc25aec5f807f@[192.168.1.2]> (raw)

Why does zsh not have "exec -l" a la bash?

Thanks

Dave

  - - - - - -

Date: Sun, 29 Apr 2007 18:25:58 -0600
To: Dave Yost <Dave@Yost.com>
Cc: openssh-unix-dev@mindrot.org
Subject: Re: setting current dir of remote shell
From: bob@proulx.com (Bob Proulx)

Dave Yost wrote:
>  Bob Proulx wrote:
>  >For me the following works:
>  >  ssh -t someserver "cd $(pwd) && exec -l \$0"
>  >  $ echo $0
>  >  -bash
>
>  I assume you mean
>
>    ssh -t someserver "cd $(pwd) && exec \$0 -l"

No, I really did mean 'exec -l \$0'.  Your transposition is similar
and will have similar effects but is not identical.  (Very close to
though, and the difference is quite subtle.)

   help exec
   exec: exec [-cl] [-a name] file [redirection ...]
       Exec FILE, replacing this shell with the specified program.
       If FILE is not specified, the redirections take effect in this
       shell.  If the first argument is '-l', then place a dash in the
       zeroth arg passed to FILE, as login does.  If the '-c' option
       is supplied, FILE is executed with a null environment.  The '-a'
       option means to make set argv[0] of the executed process to NAME.
       If the file cannot be executed and the shell is not interactive,
       then the shell exits, unless the shell option 'execfail' is set.

The magic part is:

   "If the first argument is '-l', then place a dash in the zeroth arg
   passed to FILE, as login does."

The classic /bin/login program has always placed a dash as the first
character of the shell when starting up login shells.  Shells inspect
their first argument, their own name, and look for a '-' in the
leading part of the name.  If the shell finds a '-' there then they
assume they were started by login and configure themselves as a login
shell.  Login shells read the defined list of environment files such
as /etc/profile and others.

The transposition of using 'exec \$0 -l' instead of 'exec -l \$0'
won't place a dash in the leading part of the shell's name.  Therefore
the shell won't think it is a login in the same way that it would if
it were really a login shell started by /bin/login.  However the shell
will by the -l option be told to behave as a login shell.  At that
point the shell will behave fully as a login shell and there is no
difference.  However if child programs want to deduce if the parent
shell is a login shell or not they usually look at $0, as I did in my
example, and look to see if the shell's name starts with a dash or
not.  This difference is probably insignificant but child processes
won't be able to tell if the parent is a login shell in that case.

The problem is that POSIX does not specify any options to exec and
therefore use of 'exec -l' is non-standard by definition.  I do not
know which shells support it and which do not.  Bash supports it and
so if it is known to be working with bash then it is fine to use.  But
if it must be completely portable to unspecified shells then of course
it would be a problem.

Meanwhile, the very reason I like it is that 'exec -l $SOMESHELL' can
spawn a random, unknown, unspecified shell as $SOMESHELL and guarantee
that it will be a login shell even if $SOMESHELL does not take the -l
option.  Because of the /bin/login interface of placing a leading dash
all shells will respect that interface.  The classic csh is an example
of a shell that does not accept a -l option to behave as a login
shell.  Therefore 'exec csh -l' would fail while 'exec -l csh' would
succeed in producing csh running as a login shell.  (I think newer csh
variants have added the -l option for compatibility.)

Bob


             reply	other threads:[~2007-04-30  1:15 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-04-30  0:52 Dave Yost [this message]
2007-04-30  2:33 ` Geoff Wing
2007-04-30  2:48 ` Phil Pennock
2007-04-30  4:39 ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='pdy98830624081fc25aec5f807f@[192.168.1.2]' \
    --to=dave@yost.com \
    --cc=bob@proulx.com \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).