Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Linux bash 脚本:
函数打印() { 回声 $1 } 打印“确定”
此脚本运行成功,直接执行时,使用 sudo 运行时出错:
alex@alex-linux:~/tmp$ ./sample-script 好的 alex@alex-linux:~/tmp$ sudo ./sample-script [sudo] 亚历克斯的密码: ./sample-script: 1: 语法错误:"(" 意外
为什么?
你有
#!/bin/bash
作为脚本的第一行?这可能需要
也许 root 有一个不支持该语法的不同默认 shell。