[英]Script doesn't work when executed with sudo
Linux bash script: Linux bash脚本:
function Print() { echo $1 } Print "OK"
This script runs successfully, when executed directly, and gives an error running with sudo: 此脚本在直接执行时成功运行,并使用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? 为什么?
do you have 你有
#!/bin/bash
as the first line of the script? 作为脚本的第一行? this may be needed 这可能是必要的
也许root有一个不同的默认shell,不支持该语法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.