【发布时间】:2019-10-20 00:52:09
【问题描述】:
我有一个 bash 脚本,它创建一个新用户并将当前的 $USER 添加到新创建的用户组。然后我想使用 newgrp 重新启动脚本,以便 shell 对新用户拥有的文件具有读/写权限。
我希望终端机上的人能够响应一些输入。当我使用newgrp 重新启动脚本时,read 不再有效。它完全被绕过了。
我在下面包含了一个显示相同行为的示例。
do_restart_script_with_updated_permissions () {
local cwd=$(pwd)
export SCRIPT_PATH="$cwd"
newgrp "newgroup" <<EONG
export NEW=true
cd $SCRIPT_PATH
./test.sh
EONG
}
if [ -z "$NEW" ]; then
echo "We will restart the script."
read
do_restart_script_with_updated_permissions
else
echo "Script restarted."
# this does nothing
read -p "get some input" user_input
echo "Done."
fi
这是脚本的输出:
./test.sh
We will restart the script.
Script restarted.
Done.
【问题讨论】:
标签: bash