I'm getting kinda stuck, here. I have a small script that will be incorporated into a larger script. This small piece is supposed to take a user input, and compare it to a list of stored variables. If the user input matches one of the listed variables, it should output the string that is that variable; or, if it matches none of the elements, then it should write the user input to a new variable.
For context, what I've done is I've defined a few variables as strings (in this case, the citation information for textbooks). As an example:
books=() buffa7="Wilson, Buffa, Lou. Physics. Pearson, 7th edition, 2009. ISBN: 0321601831" books=+("$buffa7") giancoli6="Giancoli, Douglas C. Physics: Principles with Applications. Prentice Hall, 6th edition. ISBN: 0321736990" books=+("$giancoli6")
My understanding of this code is that it will make an array,
books, and take the variables
$giancoli6 and append them to the list. What I'd like to do is prompt a user for input on the source: if they input
giancoli6, then the variable
$source should be redefined to be the text assigned to the respective variable. If the user input does not match these, then the variable
$source should be defined to be whatever the user input.
The problem I seem to be running into is that when the user inputs the source information, if they use
buffa7, bash seems to think that if the actual string
buffa7 is not in its list, then it doesn't have to do anything, and thinks that
buffa7 is not in the list (which is true, because
$buffa7 is). Any advice on how to proceed would be much appreciated!