定义多个文件我需要执行一个适用于多个文件的exec命令,但它不起作用。我将创建一个示例来展示这一点。很显然,我并不需要此目录的任何东西,我做的“ls”命令的例子,虽然与其他任何命令发生:php exec命令不允许使用{}
exec("ls -al /etc/security/", $output);
print_r($output);
Array
(
[0] => total 40
[1] => drwxr-xr-x 2 root root 4096 Jan 27 2010 .
[2] => drwxr-xr-x 83 root root 4096 Feb 24 12:38 ..
[3] => -rw-r--r-- 1 root root 4266 Apr 9 2008 access.conf
[4] => -rw-r--r-- 1 root root 3551 Apr 9 2008 group.conf
[5] => -rw-r--r-- 1 root root 1911 Apr 9 2008 limits.conf
[6] => -rw-r--r-- 1 root root 1507 Apr 9 2008 namespace.conf
[7] => -rwxr-xr-x 1 root root 977 Apr 9 2008 namespace.init
[8] => -rw------- 1 root root 0 Jan 27 2010 opasswd
[9] => -rw-r--r-- 1 root root 2980 Apr 9 2008 pam_env.conf
[10] => -rw-r--r-- 1 root root 2180 Apr 9 2008 time.conf
)
但随着更多文件尝试...
exec("ls -al /etc/security/{access.conf,group.conf}", $output);
print_r($output);
ls: cannot access /etc/security/{access.conf,group.conf}: No such file or directory
当然这作品在控制台:
$ ls -al /etc/security/{access.conf,group.conf}
-rw-r--r-- 1 root root 4266 2008-04-09 15:25 /etc/security/access.conf
-rw-r--r-- 1 root root 3551 2008-04-09 15:25 /etc/security/group.conf
我认为问题在于'{}'被shell **而不是'ls'命令扩展**。 PHP的'exec'不会穿过一个shell,或者至少不是同一种shell,因此不会扩展速记。 – deceze 2011-02-25 01:58:29
所以...无论如何解决它? ;) – FlamingMoe 2011-02-25 02:03:12