I have a problem with the following command
sudo -u ${USER} -H sh -c "bash ${START_SCRIPT}"
I can exclude errors with the START_SCRIPT, since
bash ${START_SCRIPT}
works excellent.
I think there must be a problem with the sudo-syntax, but I can't find the answer. Everywhere (eg this link , answer by Kimvais or the sudo manpages) suggest the formatation I used above.
USER=some_user START_SCRIPT=/some/long/path/start.sh
I can only guess that it has to do with the long path or that I miss any arguments for the sudo-command.
In this thread I read:
sudo -H -u otheruser bash -c 'echo "I am $USER, with uid $UID"'
That works perfectly, but neither
sudo -H -u otheruser bash -c '${START_SCRIPT}'
nor
sudo -H -u otheruser -c 'bash "${START_SCRIPT}"'
works.
Can anyone help me please or at least give a hint?
The single quotes in
sudo -H -u otheruser bash -c '${START_SCRIPT}'
prevent the shell from expanding the $
. Simply use double quotes:
sudo -H -u otheruser bash -c "${START_SCRIPT}"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.