Sample Header Ad - 728x90

Do `[[ ]]` and `(( ))` have "transitive evaluation" of variables?

2 votes
1 answer
242 views
I am using bash, version:
GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)
I made a following script:
#!/usr/bin/bash

a=11
b=4
c=7+b

if [[ a -eq c ]]
then
    echo "ok"
else 
    echo "not ok"
fi
It prints "ok". When I change a to 10, it prints "not ok". So I have a simple question, do [[ ]] and (( )) makes "transitive evaluation" (in my example, that would mean c first evaluates to 7+b and then b evaluates to 4 and finally it overall becomes 11)? I ask because I have a serious "fight" with AIs (chatGPT, gemini, claude), where they say that this kind of evaluation does not happen, but my examples show otherwise (they say that c is evaluated to 7+b, and since it is not a number, the value 0 is taken)... Thanks in advance
Asked by Yakog (517 rep)
Feb 17, 2025, 11:40 AM
Last activity: Feb 17, 2025, 04:07 PM