I have a script with around 12 variables that do multiple checks on a user that is passed to my script with $1
. What I would like to do is to be able to call a variable from the command line with $2
. So for example I have variables in my script like so:
!#bin/bash
var1=blah0
var2=blah1
var3=blah2
var4=blah3
What I want is to be able to run the script like $ ./script.sh user var3
and that should return the value that the variable holds. Without doing a bunch of if then statements, how could I do this efficiently? I've tried arrays but I couldn't figure out how to pass a variable inside the array.