Trying to execute the source command using "lfs" user on ubuntu 14.04 and getting this:

root@linux:~/lfs# su lfs - -c "source ~/.bash_profile"
bash: cannot set terminal process group (-1): Inappropriate ioctl for device
bash: no job control in this shell

Any ideas?

Background info: I am following the LFS book, making a script out of it, so in my script which I execute with sudo, when it gets to this part, after creating the lfs user and his .bashrc and .bashprofile, I guess it is loading it.


echo "info: create 'lfs' group and user..."
groupadd -f lfs
id -u lfs &>/dev/null || useradd -s /bin/bash -g lfs -m -k /dev/null lfs
passwd -d -q lfs

echo "info: make 'lfs' own the 'tools' and 'sources' directories..."
chown lfs $LFS/tools
chown lfs $LFS/sources

echo "info: creating a clean '.bash_profile' as user 'lfs'..."
su lfs - -c "cat > ~/.bash_profile << \"EOF\"
exec env -i HOME=$HOME TERM=$TERM PS1='\u:\w\$ ' /bin/bash

echo "info: creating a clean '.bashrc' as user 'lfs'..."
su lfs - -c "cat > ~/.bashrc << \"EOF\"
set +h
umask 022
LFS_TGT=$(uname -m)-lfs-linux-gnu

su lfs - -c "source ~/.bash_profile"


It has been suggested that my syntax is incorrect, I am not at my linux machine at the moment, so will try to use different syntax when I get the chance. However, for info, I got the syntax from the answer here: https://serverfault.com/questions/411307/cannot-set-terminal-process-group-during-su-to-another-user-as-login-shell

  • Do you want su to run bash as if it were a login shell? If so, then try su - lfs -c ... or su --login lfs -c ... or su lfs --login -c .... Nov 21 '16 at 19:38
  • 1
    @MarkPlotnick That gives the same error.
    – sprocket12
    Nov 21 '16 at 20:15
  • su - username runs the login shell of username as an interactive shell.

  • su username command arguments runs command arguments non-interactively under the account username.

You command su lfs - -c "source ~/.bash_profile" means run - -c "source ~/.bash_profile" as the user lfs non-interactively. Now the shell sees the option - and says, I am to run as an interative login shell, and tries to initialize the terminal, but su has disconnected the child process from the controlling terminal.

In short: The - is either misplaced or erroneous.

For a longer discussion, see practically the the same question on serverfault.

  • What do you mean by “run … non-interactively”? And by “su has disconnected the child process from the controlling terminal”? Either you're using the wrong terminology (but I can't figure out what you're intended) or you're confused as to what is going on. Nov 21 '16 at 23:50
  • 1
    Summary: the correct syntax is either su username command arguments, su username, or su - username. The form used by the original poster, su username - command arguments is incorrect.
    – AlexP
    Nov 22 '16 at 6:51
  • @AlexP Thanks for your reply. Why do you think the previous lines in the script work? They use the same syntax.
    – sprocket12
    Nov 22 '16 at 9:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.