I'm trying to use the tput command in a bash script if statement but for some reason it's behaving unexpectedly. When running the command and then checking the exit code only in the if statement things work correctly, however, when running the command in the if statement directly things no longer work. Here's a simple script to illustrate my issue:
#!/bin/bash tput setaf 1 if [ $? ] then echo "first if works" fi if tput setaf 1 then echo "second if works" fi
Running this script only prints "first if works". Shouldn't both of these if statements work since they are equivalent? Am I missing something? BTW, this is running on FreeBSD in case that matters.