I want to manipulate the expanded value of a variable that has been selected from an array after user input. Here's what I mean:
$ ./myscript.sh url2
#!/bin/bash array=(Sigil wp2epub csskit) Sigil = "https://github.com/Sigil-Ebook/Sigil.git" csskit = "https://github.com/mattharrison/epub-css-starter-kit.git" wp2epub = "https://github.com/mrallen1/wp2md.git" if [ -z $1 ]; then echo "This script needs at least one parameter!" exit 1 fi if [ $1 = Sigil ]; then ans=$Sigil # expanded elif [ $1 = csskit ]; then ans=$csskit # expanded elif [ $1 = wp2epub ]; then ans=$wp2epub # expanded else echo "Please inform one of \ Sigil, csskit or wp2epub!" fi git clone $ans
Explanation:
The script checks user input ($1), compares it to the array of possible variables, if found it retrieves the expanded value of that variable as the answer and then uses the expanded value (not the variable name).
I have been trying this for days, but my limited bash scripting abilities have not been enough...
Thanks in advance.
Per @terdon request: I want the user to inform the name of the variable in the array, which will be human friendly.
The variables are actually the names of packages that need to be fetched from github (git clone) and then recompiled and reinstalled.
Actual usage would be:
$ ./update.sh Sigil # Sigil is one of the variables
$urlN
variables. What are the "expanded values"? Do you want the user to enterwww.example.com
and your script to retrieve a value linked to that URL? Or do you want your user to enter a string and the script to retrieve the URL associated with that script? Are you thinking of having your user enter the stringurl1
and have that expanded to$url1
in your script?if
s meant to beelif
s?fi
, the variousif
should probably beelif
etc) and your indentation made even less sense since it looked like there were nested contradictoryif
clauses.fi
s) but fair enough