Reputation: 51
Sorry for the silly question here today.
I am passing a PHP array to a bash script using implode();
.
To test, I am echoing the implode and I can see all array items there, but when I printf '%s\n' "${files[@]}"
only the first element of the array is printed.
Am I missing something?
Here is more info:
PHP:
$files = $_POST['files'];
$files2 = implode(" ", $files);
echo $files2 ## I can see full output here.
shell_exec ("./sequential.sh $files2");
Bash:
files = $1
printf '%s\n' "${files[@]}" >> mytempfile.txt
Thanks for any guidance.
Upvotes: 1
Views: 79
Reputation: 72226
files = $1
$1
is only the first argument. If you want all arguments then you can find them in $@
:
printf '%s\n' "$@" >> mytempfile.txt
Upvotes: 1