helpThe GNU Bourne-Again SHell - Support: sr #109672, conditional expression and...

 
 

sr #109672: conditional expression and associative array expansion bug

Submitted by:  None
Submitted on:  Wed 17 Apr 2019 05:02:55 PM UTC  
 
Category:  None Priority:  5 - Normal
Severity:  4 - Important Status:  Invalid
Privacy:  Public Assigned to:  None
Originator Email:  -email is unavailable- Open/Closed:  Open
Operating System:  GNU/Linux

Add a New Comment (Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Fri 19 Apr 2019 02:42:05 PM UTC, comment #1: 

This isn't a bug. The array subscript gets expanded so side effects take place. Since the variable isn't set, the default is an indexed array, and the subscript is expanded as an arithmetic expression. IP is a token that looks like a variable, so it gets expanded and replaced with its value. /sbin/ip is not a valid token or operator, so you get an arithmetic syntax error.

It doesn't require that __client be unset; declaring __client as an indexed array would produce the same error.

Chet Ramey <chet>
Project Administrator
Wed 17 Apr 2019 05:02:55 PM UTC, original submission:  

The following code:

#!/bin/bash -x

IP="/sbin/ip"

if [[ ${__client[IP]} ]]; then
        echo "Boink!"
fi

Generates the following output:

+ IP=/sbin/ip
./test.sh: line 5: /sbin/ip: syntax error: operand expected (error token is "/sbin/ip")

It only happens if the "__client" is unset.

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by chet (Posted a comment)
  • -email is unavailable- added by None (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

     

     

    Follows 1 latest change.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-04-19 chet StatusNone => Invalid

    Back to the top


    Powered by Savane 3.5