我有一个脚本launch.sh
,该脚本可以另一个用户身份执行,以便使用正确的所有者创建文件。我想将-x传递给此调用(如果它最初传递给脚本)
if [ `whoami` == "deployuser" ]; then
... bunch of commands that need files to be created as deployuser
else
echo "Respawning myself as the deployment user... #Inception"
echo "Called with: <$BASH_ARGV>, <$BASH_EXECUTION_STRING>, <$->"
sudo -u deployuser -H bash $0 "$@" # How to pass -x here if it was passed to the script initially?
fi
我已经阅读了bash调试页面,但是似乎没有明确的选项可以告诉您原始脚本是否使用来启动-x
。
[[ $- == *x* ]]
用于模式匹配。