使用 sudo 执行时脚本不起作用
Linux bash脚本:
function Print() { echo $1 } Print "OK"
这个脚本运行成功,直接执行时,用sudo运行却报错:
alex@alex-linux:~/tmp$ ./sample-script OK alex@alex-linux:~/tmp$ sudo ./sample-script [sudo] password for alex: ./sample-script: 1: Syntax error: "(" unexpected
为什么?
Linux bash script:
function Print() { echo $1 } Print "OK"
This script runs successfully, when executed directly, and gives an error running with sudo:
alex@alex-linux:~/tmp$ ./sample-script OK alex@alex-linux:~/tmp$ sudo ./sample-script [sudo] password for alex: ./sample-script: 1: Syntax error: "(" unexpected
Why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你有
脚本的第一行吗?这可能需要
do you have
as the first line of the script? this may be needed
也许 root 有一个不同的默认 shell,不支持该语法。
Perhaps root has a different default shell that doesn't support that syntax.