开发者

Script doesn't work when executed with sudo

开发者 https://www.devze.com 2022-12-23 02:51 出处:网络
Linux ba开发者_开发知识库sh script: function Print() { echo $1 } Print \"OK\" This script runs successfully, when executed directly, and gives an error running with sudo:

Linux ba开发者_开发知识库sh 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?


do you have

#!/bin/bash

as the first line of the script? this may be needed


Perhaps root has a different default shell that doesn't support that syntax.

0

精彩评论

暂无评论...
验证码 换一张
取 消