1

I have the following script:

brews=(
  java8
  archey
  aws-shell
  "bash-snippets --without-all-tools --with-weather"
  cheat
  coreutils
  dfc
  findutils
  "fontconfig --universal"
  fpp
  fzf
  git
  bash-completion
  git-extras
  git-fresh
  git-lfs
  "gnuplot --with-qt"
)

casks=(
  adobe-acrobat-reader
  airdroid
  android-platform-tools
  awscli
  cakebrew
  cleanmymac
  commander-one
  docker
  dropbox
  firefox
  geekbench
  google-backup-and-sync
  google-chrome
  github
  handbrake
  hyper
)

function install {
  cmd=$1
  shift
  for pkg in "$@";
  do
    exec="$cmd $pkg"
    if ${exec} ; then
      echo "Installed $pkg"
    else
      echo "Failed to execute: $exec"
    fi
  done
}


install 'brew install' ${brews[@]}
install 'brew cask install' ${casks[@]}

When I execute it, I notice it is splitting up things like gnuplot --with-qt e.g. I see it try to execute: brew install --with-qt

What am I doing wrong??

4
  • 4
    You have to put double quotes around ${brews[@]} and ${casks[@]}. Commented Jun 7, 2018 at 22:07
  • shellcheck automatically detects this issue Commented Jun 7, 2018 at 22:09
  • @BenjaminW. That worked! Can you add your answer so I can accept it?
    – pathikrit
    Commented Jun 7, 2018 at 22:31
  • 1
    Especially the second answer at the "spaces in elements" duplicate. Commented Jun 7, 2018 at 22:38

0

Browse other questions tagged or ask your own question.