我正在尝试做这样的事情:
function install {
cmd=$1
shift
for pkg in "$@";
do
if $cmd $pkg; then
echo "Installed $pkg"
else
echo "Failed to install $pkg"
fi
done
}
brews=(git node scala sbt zsh caskroom/cask/brew-cask)
casks=(dropbox google-chrome spotify)
install 'brew install' $brews
install 'brew cask install' $casks
但是,这仅适用于每个数组的第一个元素。为什么不拾取其余的数组元素?