Can't seem to get this to evaluate to true
is_equal () {
in="$1"
if [[ "$in" == "385" ]]; then
return 0
else
return 1
fi
}
a= is_equal 385
if [[ "$a" ]]; then
echo "equal"
else
echo "NOT equal"
fi
$ ./equal_nums.sh
NOT equal
$
Your function has an exit status but no output. Your variable $a will always be empty, so the [[ $a ]] test will always be "false"
You truly want this:
if is_equal 42; then ...
But what you think you want is this
is_equal 42 # don't capture the output
a=$? # but do grab the exit status
if [[ $a -eq 0 ]]; then ...
a=$(is_equal 385)But as for me better useif is_equal 365 ; then ...$( is_equal ..).==is a string or pattern comparison;-eqis for integers...if test ... return ...so the function can beis_equal() { [[ "$1" -eq "385" ]] }