I have generated multiple statements via for loop those statements has to be executed and store each result in a variable using shell script
for example :
ls
ls -l /abc
ls -l /def
Output : 1 is success and 0 is failure
Command1:0
Command2:1
Command3:0
store_result() { declare -g -a results; local retval; "$@"; retval=$?; results+=( "$retval" ); return "$retval"; }-- thereafter,store_result ls; store_result ls -l /abc; store_result ls -l /defand yourresultsarray will have the desired values.