spr*_*t12 11 bash source ubuntu su lfs
尝试在 ubuntu 14.04 上使用“lfs”用户执行源命令并得到:
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
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
背景信息:我正在关注 LFS 的书,用它制作一个脚本,所以在我用 sudo 执行的脚本中,当它到达这部分时,在创建 lfs 用户和他的 .bashrc 和 .bashprofile 之后,我猜它正在加载它。
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
EOF"
echo "info: creating a clean '.bashrc' as user 'lfs'..."
su lfs - -c "cat > ~/.bashrc << \"EOF\"
set +h
umask 022
LFS=/mnt/lfs
LC_ALL=POSIX
LFS_TGT=$(uname -m)-lfs-linux-gnu
PATH=/tools/bin:/bin:/usr/bin
export LFS LC_ALL LFS_TGT PATH
EOF"
su lfs - -c "source ~/.bash_profile"
Run Code Online (Sandbox Code Playgroud)
有人建议我的语法不正确,我现在不在我的 linux 机器上,所以有机会时会尝试使用不同的语法。但是,有关信息,我从这里的答案中得到了语法:https : //serverfault.com/questions/411307/cannot-set-terminal-process-group-during-su-to-another-user-as-login-贝壳
su - username
将 的登录 shellusername
作为交互式 shell 运行。
su username command arguments
在帐户下以command arguments
非交互方式运行username
。
您的命令su lfs - -c "source ~/.bash_profile"
意味着- -c "source ~/.bash_profile"
以lfs
非交互方式以用户身份运行。现在 shell 看到该选项-
并说,我将作为交互式登录 shell 运行,并尝试初始化终端,但su
已断开子进程与控制终端的连接。
简而言之:-
要么放错了地方,要么是错误的。
有关更长的讨论,请参阅有关 serverfault 的几乎相同的问题。