"su - lfs" vs "su lfs" - su starts subshell, useless for automating in scripts..

armencho at gmail.com armencho at gmail.com
Mon Nov 26 22:55:22 PST 2007

Hi all,

I am building my own little automated LFS install script in Bash.
Basically its a copy-paste job from LFS book, of course, with minor
corrections for function.

One of the things i find difficult to script is a "nice" (read pretty)
way of continuing the install script after doing "su - lfs". the 'su'
command apparently starts a subshell process, and so the new subshell
just waits for user action, pausing the whole install script that
started the 'su'. And I cannot make it continue with the script as the
'lfs' user, since, well su just blocks, and that is the way it works.

Why can't the book just silently change user id instead ?

I could alternatively do a 'su -c ./lfs-continue - lfs', essentially
passing control further via another script, but then again, i also
have variables that i need the 'lfs' user shell inherit, which I
create on my own, for different purposes. Things like timeout values,
etc... (not part of LFS, although the $LFS variable would be nice to
have exported).

Also, is it necessary to have the hyphen in 'su' ? One can start a
clean environment session using 'su lfs' and then just executing
~/.bash_profile anyway, the difference is, apparently non-login shells
inherit variables from parent shells, while login shells do not..

More information about the lfs-support mailing list