$val will contain the return code from ls.
[system] uses a sub-shell
One of those statments is necessarily false. If a shell is used, $val will contain the return value of the shell, not ls.
So does system use a shell? It depends. "If there is only one scalar argument, the argument is checked for shell metacharacters, and if there are any, the entire argument is passed to the system's command shell for parsing." Otherwise, no.
In this case? no. However, I still wouldn't use ls.
Some examples:
system('command foobar') # no shell system('command "foo bar"') # shell system('command', 'foo bar') # no shell system('sort < file | uniq') # shell
In reply to Re^2: how to store values from system command
by ikegami
in thread how to store values from system command
by veeruch
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |