bashsupport-pro icon indicating copy to clipboard operation
bashsupport-pro copied to clipboard

In bash, ${diskSize:=0} is a variable assignment and default value setting command, but it is not recognized properly?

Open super-vip opened this issue 9 months ago • 1 comments

image

super-vip avatar May 06 '24 03:05 super-vip

I can confirm that this is a bug. I'll fix it for the next update. It's happening because ${diskSize:=0} is inside a subshell and here BashSupport Pro is not applying the correct scoping.

The following works as expected:

diskSize=42
echo ${diskSize:=0}

jansorg avatar May 06 '24 09:05 jansorg

This is fixed now for the next update

jansorg avatar May 13 '24 14:05 jansorg

image Inline arrays seem to have this problem?

super-vip avatar May 14 '24 16:05 super-vip

@super-vip Yes, unfortunately that's a known issue. As a workaround, please quote the keys, e.g. ["red"]. (Please create new issue if it's not related to the current issue)

Bash determines at runtime how to interpret [red]. For indexed arrays, it's an arithmetic expression (and red would be a variable) and for associative arrays red is a string value.

Here's an example:

#!/usr/bin/env bash
red=1
declare -a colorsIndexed
declare -A colorsAssociative
colorsIndexed=(
    [red+10]="this is red+10"
)
colorsAssociative=(
    [red+10]="this is red+10"
)
declare -p colorsIndexed
declare -p colorsAssociative

Output:

declare -a colorsIndexed=([11]="this is red+10")
declare -A colorsAssociative=([red+10]="this is red+10" )

jansorg avatar May 14 '24 18:05 jansorg

Version 4.1.1 with the fix for the parameter expansion is now available.

jansorg avatar May 15 '24 20:05 jansorg

Great, thank you. Upon testing, it has been confirmed that this issue has been resolved.

super-vip avatar May 16 '24 00:05 super-vip