代码之家  ›  专栏  ›  技术社区  ›  pathikrit

如何在Bash中传递带有空格作为函数参数的数组[duplicate]

  •  1
  • pathikrit  · 技术社区  · 7 年前

    我有以下脚本:

    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[@]}
    

    gnuplot --with-qt e、 我看到它试图执行: brew install --with-qt

    我做错什么了??

    0 回复  |  直到 7 年前