
Das ist, was ich jetzt versuche
In PHP führe ich das folgende Skript aus:
exec('/home/user1/createinstanceinfolder.sh', $output, $return_var);
print_r($output);
Dadurch wird das folgende Bash-Skript aufgerufen:
declare -A arr == $(sudo mysql -u root -h localhost -e "USE mydb;SELECT * FROM users")
for i in "${arr[@]}"
do
echo "$i"
done
PHP druckt ein leeres Array, was ist hier falsch?
Antwort1
Ich finde, die richtige Syntax ist:
#!/bin/bash
set -f # disable globbing
IFS=$'\n' # set field separator to NL (only)
arr=($(sudo mysql -u root -h localhost -e "USE mydb;SELECT * FROM users"))
for i in "${arr[@]}"
do
echo "$i"
done