【发布时间】:2016-01-08 08:55:47
【问题描述】:
我有一个 perl 脚本如下: 测试.pl
#!/usr/bin/perl
system("ls -lart");
这很好,但是当我按如下方式运行它时它失败了:
su guest test.pl
它在第二行失败,如下所示:
0403-057 Syntax error at line 2 : `(' is not expected.
【问题讨论】:
我有一个 perl 脚本如下: 测试.pl
#!/usr/bin/perl
system("ls -lart");
这很好,但是当我按如下方式运行它时它失败了:
su guest test.pl
它在第二行失败,如下所示:
0403-057 Syntax error at line 2 : `(' is not expected.
【问题讨论】:
来自man 1 su:
OPTIONS
The options which apply to the su command are:
-c, --command COMMAND
Specify a command that will be invoked by the shell using its -c.
The executed command will have no controlling terminal. This option cannot be used to execute interractive programs which need a controlling TTY.
所以你应该使用
su -c "perl /path/to/test.pl --maybe some.options" guest
【讨论】:
您必须使用su 的-c 选项来执行它。问题是,如果你这样启动它,它应该是一个 shell 脚本。所以你必须告诉su实际加载shell然后执行命令。
很有可能
su guest -c test.pl
会起作用(当然,前提是它在用户的命令路径中)。
【讨论】: