Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

variable substitution (what do you call/name this method)?

Tags:

variables

bash

Say in bash I have:

c=3

b3=4

instead of:

echo $b3 

what kinda of command to have output of "4" ? I tried below but couldn't.

  1. echo $b($(c))

  2. echo $b{!c}

  3. echo $b${c}

  4. echo ${d[$c]}

like image 803
beavis11111 Avatar asked Apr 26 '26 09:04

beavis11111


1 Answers

You can use an indirect reference for that:

$ c=3
$ b3=4
$ d=b$c
$ echo "${!d}"
4

Although usually instead of indirect references, arrays should be used when possible.

like image 148
user000001 Avatar answered Apr 28 '26 10:04

user000001



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!