简体   繁体   English

sudo在shell中不起作用

[英]sudo won't work in shell

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 我可以排除START_SCRIPT的错误,因为

bash ${START_SCRIPT}

works excellent. 效果很好。

I think there must be a problem with the sudo-syntax, but I can't find the answer. 我认为sudo语法肯定有问题,但是我找不到答案。 Everywhere (eg this link , answer by Kimvais or the sudo manpages) suggest the formatation I used above. 任何地方(例如, 此链接 ,Kimvais的答案或sudo手册页)都建议我上面使用的格式。

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. 我只能猜测这与长路径有关,或者我错过了sudo命令的任何参数。

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 $ . 防止shell扩展$ Simply use double quotes: 只需使用双引号:

sudo -H -u otheruser bash -c "${START_SCRIPT}"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM