bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#59612: Incorrect behavior also with ${CONDITION}


From: Milan Zimmermann
Subject: bug#59612: Incorrect behavior also with ${CONDITION}
Date: Sat, 26 Nov 2022 11:19:08 -0500

I should add that I realized using {CONDITION} alone is not a reasonable thing in my examples, as it uses exist status.

In a real code, one would use  ${CONDITION}. The modified script is attached below #####. However, the behavior is still not as expected:

~/tmp $ source ./conditionals-bug.esh
It is 2
It is 3
It is NOT 3
It is 4
It is NOT 4


######################################
# The behavior of conditionals depends on whitespace
# Source this script to test it

# This formatting works as expected; evaluates the "true" block.
# Result:
#  "It is 2"
#

if ${= 2 2} {
  echo "It is 2"
} {
   echo "It is NOT 2"
}

# This formatting causes a BUG: both the "true" block and the "false" block are evaluated.
# I tried several combinations, it appears it the "false" block starts on it's own line,
# it is no longer treated a part of the "if" _expression_. Which could be argued
# is expected because there is no "else" that would define whether the second block
# is not part of the "if" _expression_. BUT see next test
#
# Result:
#  "It is 3"
#  "It is NOT 3"
#

if ${ = 3 3 } {
   echo "It is 3"
}
{
   echo "It is NOT 3"
}

# BUT we get the same incorrect result if we place the whole if _expression_ into {}
{
  if ${ = 4 4 } {
     echo "It is 4"
  }
  {
     echo "It is NOT 4"
  }
}

reply via email to

[Prev in Thread] Current Thread [Next in Thread]