I need to do an exec command that applies to several files, but it's not working. I'm going to create an EXAMPLE to show this. Obviously, I don't need anything of this directory and I do the example with "ls" command, although happens with any other command:
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
)
But trying with more files ...
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
Of course this works in console:
$ 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
{}is expanded by the shell, not by thelscommand. PHP'sexecdoesn't go through a shell, or at least not the same kind of shell, hence doesn't expand the shorthand.