I get the name of a variable from the script user as the first argument and I echo the value of said variable back to the console:
#!/bin/bash
variablename=$1
echo "The value of $variablename is: " ${!variablename}
This works great!
What I can't get to work is if I want to change that variable into the value of the second argument from the user. An example with a syntax error is:
#!/bin/bash
variablename=$1
echo "The value of $variablename is: " ${!variablename}
echo "I will now try to change the value into $2."
(!variablename}=$2
# The above line generates: {!variablename}=2: command not found
In other words: If it is possible, how do I get a variable name from the user and both read (already solved) and write to said variable?