I cannot understand the logic of what's going on with this simple Bash script:
#!/bin/bash
Check if file is present
which ./vendor/bin/non_existent_file &> /dev/null
printf "Exited with $?\n\n"
if [[ "$?" -eq 1 ]]; then
echo "Number is One"
else
echo "Number is not one"
fi
When the file is missing (non existent), the output is this:
Exited with 1
Number is not one
When the file is present, the output is this:
Exited with 0
Number is not one
???
Things I've tried:
if [ $? == 1 ]
if [ "$?" == 1 ]
if [[ "$?" == 1 ]]
if [[ $? -eq 1 ]]
if [[ "$?" = "1" ]]
if [[ "$?" == "1" ]]
Why is the IF statement always failing?