What's the best way to convert a literal string (e.g. "True" into the appropriate bash boolean variable). For instance java has java.lang.Boolean.valueOf(String)
Right now I'm using this in Bash:
if [ "${answers[2]}" = "TRUE" ] ; then
clean=true;
else
clean=false;
fi
is there a way to do it and avoid the IF statement?
edit: to clarify its not by choice that I have String variable containing "TRUE" instead of just using a boolean variable. for full context this is the code
ans=$(yad --title='YadExample' --form --field=Opt1:CHK FALSE --field=Opt2:CHK FALSE --field=Opt3:CHK TRUE);
#at this point the "yad" program is returning a string seperated by '|', e.g "TRUE|FALSE|TRUE"
IFS="|"
set -- $ans
answers=( $@ )
unset IFS
if [ "${answers[0]}" = "TRUE" ] ; then clean=true; else clean=false; fi
if [ "${answers[1]}" = "TRUE" ] ; then var2=true; else var2=false; fi
if [ "${answers[2]}" = "TRUE" ] ; then var3=true; else var3=false; fi
answersarray coming from? What are possible entry values?