Hi Chet,

Summary
*******
When a variable name and its' value are the same characters (a="a"),
a recursion error occurs.

Steps to recreate "problem"
***************************

Step 1:
1. Execute the command
.....................................................................
a="cat";b="dog";[[ $a -lt $b ]]; echo $?
1
.....................................................................

Step 2:
1. Change a="cat" to a="a".
2. Execute the command
.....................................................................
a="a";b="dog";[[ $a -lt $b ]]; echo $?
bash: [[: a: expression recursion level exceeded (error token is "a")
1
.....................................................................

In the steps above, I know I am using the numeric operator -lt to
compare 2 strings, in [[]]. But a recursion error seems a little
harsh, and seems inconsistent between Step 1's results and Step 2's.
The recursion error does not occur in Step 1, but it does in Step 2.
The only thing that changed was a="cat" to a="a". On the other hand,
if it is a usage error, which [] considers it to be, shouldn't the
return status be 2, not 1.

Occurs in the following
***********************
- GNU bash, version 4.0.35(1)-release (x86_64-suse-linux-gnu)
- GNU bash, version 4.2.0(1)-release (x86_64-suse-linux-gnu)
- OpenSuSE 11.2

Additional Info
***************
I came across the above when I was running through the
scenarios below to better understand tests, evaluation,
and return codes/exit status.

 .---------------------+----------------.---------------.
 |                     |                | Return Codes  |
 |    Expression       |   Evaluates    '-------.-------'
 |  (a=5; unset b)     |                | True  | False |
 |                     |                | Succ  | Failu |
 '---------------------+----------------+-------+-------'
 | date                |                |   0   |   -   |
 | date -a 2>/dev/null |                |   -   |   1   |
 '---------------------+----------------+-------+-------'
 | (( a ))             | 5 (^1)         |   0   |   -   |
 | (( a < 4 ))         | 5 < 4 (^1)     |   -   |   1   |
 | (( a < a-1 ))       | 5 < 5-1 (^1)   |   -   |   1   |
 '---------------------+----------------+-------+-------'
 | (( $a ))            | 5 (^1)         |   0   |   -   |
 | (( $a < 4 ))        | 5 < 4 (^1)     |   -   |   1   |
 | (( $a < $a-1 ))     | 5 < 5-1 (^1)   |   -   |   1   |
 '---------------------+----------------+-------+-------'
 | [[ $a ]]            | 5 (^2)         |   0   |   -   |
 | [[ $a -lt 4 ]]      | 5 < 4          |   -   |   1   |
 | [[ $a < 4 ]]        | 5 < 4          |   -   |   1   |
 '---------------------+----------------+-------+-------'
 | (( b ))             | '' (^2)        |   -   |   1   |
 | (( $b ))            | '' (^2)        |   -   |   1   |
 | [[ $b ]]            | '' (^2)        |   -   |   1   |
 '---------------------+----------------+-------+-------'
 | [[ a ]]             | a (^3)         |   0   |   -   |
 | [[ b ]]             | b (^3          |   0   |   -   |
 |                     |                |   -   |   -   |
 |                     |                |   -   |   -   |
 |                     |                |   -   |   -   |
 |                     |                |   -   |   -   |  

 '---------------------'----------------'-------'-------'

(1) If the value of the expression is non-zero, the
    return status is 0; otherwise the return status
    is 1.

(2) The only variable regarded as false is unset or
    value is null.

(3) The (bare)word expands into word, which is neither
    null or unset, but rather the word itself.

[NOTE]
=====================================================================
- The execution of a command or program is expected to
  return an error status integer, which will be 0 (true)
  if the program completes successfully, and nonzero
  (false) if an error occurs.

  * EXIT_SUCCESS = 0
  * EXIT_FAILURE = non-zero value

- When using compound commands, the exit status of 0 and
  nonzero still stands, but there is an intermediary step
  that deals with how conditional and arithmetic expressions
  are evaluated.

- Arithmetic Evaluation ((...)): Within an expression, shell
  variables may be referenced by name without using the
  parameter expansion syntax.  
=====================================================================

Thank you.
Peggy Russell





Reply via email to