How can I make this into a loop? I have trouble with looping through variables.
WSTATUS="exited" //example output from command
VSTATUS="running"
NSTATUS="running"
JSTATUS="running"
if [[ $WSTATUS == run* ]]; then
WSTATUS=${GREEN}$WSTATUS
else
WSTATUS=${RED}$WSTATUS
fi
if [[ $VSTATUS == run* ]]; then
VSTATUS=${GREEN}$VSTATUS
else
VSTATUS=${RED}$VSTATUS
fi
if [[ $NSTATUS == run* ]]; then
NSTATUS=${GREEN}$NSTATUS
else
NSTATUS=${RED}$NSTATUS
fi
if [[ $JSTATUS == run* ]]; then
JSTATUS=${GREEN}$JSTATUS
else
JSTATUS=${RED}$JSTATUS
fi
I have tried this:
...varibles
array=( $WSTATUS $VSTATUS $NSTATUS $JSTATUS )
for value in "${array[@]}"
do
if [[ $value == run* ]]; then
WSTATUS=${GREEN}$value
else
WSTATUS=${RED}$value
fi
done
How can i iterate through bash variables, not their content? changing this wstatus into value does not work --> WSTATUS=${GREEN}$value