Ok, so this is killing me, it might sound like a simple question, but I cannot get it to work Im trying to check a command return code without storing it on a variable and simple cant.
[ $(true) ] && echo Worked
[[ $(true) ]] && echo Worked
[ $(true) -eq 0 ] && echo Worked
[[ $(true) -eq 0 ]] && echo Worked
[ "$(true)" -eq "0" ] && echo Worked
[[ "$(true)" -eq "0" ]] && echo Worked
[ $(true) -eq '0' ] && echo Worked
[[ $(true) -eq '0' ]] && echo Worked
Well, I tried pretty much every single combination, with quotes on one side, both sides, the left side, the right side... Some of them will actually output Worked but they are not actually checking the return code, if you test them with false they will also "Worked"
My final code is to run 5 commands and get the first that works, and the idea is to put them on a if/elseif statement, but I really don't want to put every single command on a variable and then check the variable, its annoying.