I found a script written in Bash that automate the installation of packages and software on a new Mac.
This is part of the script:
# helpers
function echo_ok() { echo -e '\033[1;32m'"$1"'\033[0m'; }
PACKAGES=(
vim
zsh
tree
git
)
echo_ok "Installing packages..."
brew install "${PACKAGES[@]}"
The script correctly install all of the packages listed in the array.
For testing purpose, I modified the line
brew install "${PACKAGES[@]}"
into
echo_ok "${PACKAGES[@]}"
As output I get only the first item of the array (vim
).
However, if I use
echo "${PACKAGES[@]}"
I get all the elements of the array.
It looks like the problem is passing the array in the helper function.
If I'm not mistaken, '\033[1;32m'
and '\033[0m';
have to do with the colours of the text and "$1"
is the parameter passed into that helper function. Are the double quotes important? Because I see double quote also around "${PACKAGES[@]}"
.
I'm not really sure what I'm doing wrong and why I'm not getting the entire content of the array as when used with brew install "${PACKAGES[@]}"
.