Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Script doesn't work when executed with sudo

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?

like image 768
Alex F Avatar asked Dec 13 '22 23:12

Alex F


1 Answers

do you have

#!/bin/bash

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

like image 81
Nir Levy Avatar answered Dec 18 '22 00:12

Nir Levy