Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leverage Bash associative arrays #38

Closed
dotCipher opened this issue Oct 18, 2017 · 2 comments
Closed

Leverage Bash associative arrays #38

dotCipher opened this issue Oct 18, 2017 · 2 comments

Comments

@dotCipher
Copy link
Contributor

dotCipher commented Oct 18, 2017

It might be nice to consolidate the nested if ... else ... fi blocks into an iterative loop over a bash associative array. As new installers are supported they can be added in a declarative manner instead of a deeply nested if block.

Pseudocode would look something like:

# Init
declare -a installers
installers=(
    ["Sierra"]="Install macOS Sierra.app",
    ["ElCapitan"]="Install OS X El Capitan.app",
    ["Yosemite"]="Install OS X Yosemite.app"
)
# Loop
for iso_name in "${!installers[@]}"; do
    installerExists "${installers[$iso_name]}"
    result=$?
   if [ ${result} -eq 0 ] ; then
       createISO "${installers[$iso_name]}" "${iso_name}"
       exit 0
   fi
done
# Failure
echo "Could not find any installer"
exit 1
@kylegoetz
Copy link

kylegoetz commented Mar 19, 2018

Associative arrays are only supported in Bash 4 (I think). I am running Sierra, and Sierra still has Bash 3.

Edit Yup! http://tldp.org/LDP/abs/html/bashver4.html

@geerlingguy
Copy link
Owner

Closing; it would be nice to do this at some point, but the verbosity is still necessary for backwards compatibility :(

Someday :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants