bash scripting need help getting a variable of a variable
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
bash scripting need help getting a variable of a variable
I'm not sure what the best way is to do this, but here's my best example
PORT:~$ set JOHN SAM BILL
PORT:~$ name=$3
PORT:~$ echo $name
BILL
PORT:~$ number=3
PORT:~$ name="$"${number}""
PORT:~$ echo $name
$3
If it will make a difference inside of a bash script of not I'm unsure
the first method gives me the answer I want but the number is being randomly generated, and I need to be able to get the script to pull that number from another variable if there is a better way to do this I'm all ears. I also realize that this is probably the worst application for a bash script, but my question is whether it is or is not possible. I know that C C++ would be better code
pcarrick@PORT:~$ set JOHN SAM BILL
pcarrick@PORT:~$ name=$3
pcarrick@PORT:~$ echo $name
BILL
pcarrick@PORT:~$ number=3
pcarrick@PORT:~$ name="$"$number""
pcarrick@PORT:~$ echo $name
$3
maybe I wasn't clear enough
regardless of where the variable is I want to use the value of $number to retrieve $3, I'm not sure if its possible
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.