Re: su 5.2.1 does not invoke bash as a login shell when stdin is from a pipe



Angel Tsankov <fn42551@xxxxxxxxxxxxxxxx> wrote:
Here's a scenario in which su from coreutils 5.2.1 does not
invoke bash as a login shell:


[ piping commands to su ]

As a workaround, pass '-l' through to the shell:

# echo 'echo $PATH' | su - -- USER -l

Dave, this is the first workaround that comes around! How does it
work?


Arguments after the user name are passed directly to the shell, the -l
just tells the shell to behave like a login shell.

The '--' is needed to prevent the GNU getopt_long library function
re-organising the command line (the default behaviour would be for
"su - USER -l" to be transformed to "su -l - USER").
.



Relevant Pages