help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-bash] Non-interactive login shell does not use /etc/profile


From: John Lane
Subject: [Help-bash] Non-interactive login shell does not use /etc/profile
Date: Fri, 13 Jan 2017 14:48:18 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.6.0

If you start a bash non-interactive login shell using the leading hyphen
method then the /etc/profile is not used. It is used if the -l option is
used or if the hyphen method is used with an interactive shell.

Strictly bash's behaviour is in line with its documentation because that
does not describe how it behaves with a leading hyphen. However, it
isn't what other shells do (zsh and dash, for example, work as expected)
or what other commands expect a shell to do.

My specific use case is, I would assume, quite common: launching a
command using `su -`, as in

    $ su - someuser -c cmd

where someuser's shell is bash.

The man-page for su explains that its hyphen option "sets argv[0] of the
shell to - in order to make the shell a login shell".

To reproduce the problem:

    $ (PATH= exec -a '-' /usr/bin/bash -c 'echo $PATH')

will not set $PATH, Whereas

    $ (PATH= exec /usr/bin/bash -l -c 'echo $PATH')

to be consistent with above, but put simply:

    $ PATH= /usr/bin/bash -l -c 'echo $PATH'

works as expected.

Just wondering whether this is a bug or by design ?

GNU bash, version 4.4.5(1)-release (x86_64-unknown-linux-gnu)
Arch Linux 4.8.13-1-ARCH #1 SMP PREEMPT Fri Dec 9 07:24:34 CET 2016
x86_64 GNU/Linux




reply via email to

[Prev in Thread] Current Thread [Next in Thread]