First you must debug the PHP script to create valid array content, the code
print $associativeArray;
just you get the following result:
$ php test.php Array
You can simply print the associative array in a foreach loop:
foreach ( $associativeArray as $key=>$val ){ echo "$key:$val\n"; }
containing a list of variable names + content separated by a ':'
$ php test.php BASE_PATH:1 db_host:2 db_name:3 db_user:4 db_pass:5
As for the shell script , I suggest using simple and straightforward shell constructs, and then move on to advanced ones (for example, ${#result}
) to use them correctly.
I tried the following bash script to get variables from a php script output to shell script:
# set the field separator for read comand IFS=":"
source share