Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BASH using double variable $ - bad substitution [duplicate]

From my code below, how to make the value of 'zz' become 500 after replacing 'critical_' with x on variable 'yy'

xab123=500

yy="critical_ab123"
zz=${"${yy//critical_/x}"}

echo $zz

instead the result, there is an error:

line 8: ${"${yy//critical_/x}"}: bad substitution

thanks adi

like image 574
adiwhy Avatar asked Jan 11 '23 10:01

adiwhy


1 Answers

May be like this:

xab123=500
yy="critical_ab123"
zz="${yy//critical_/x}"
echo ${!zz}
500
like image 187
anubhava Avatar answered Jan 18 '23 14:01

anubhava