bash - 如何在 Bash 中将带有空格的数组作为函数参数传递
问题描述
我有以下脚本:
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
例如我看到它尝试执行:brew install --with-qt
我究竟做错了什么??
解决方案
推荐阅读
- php - 用php创建动态页面
- css - 是否有包含输入的输入字段的 CSS 选择器?
- python - Pandas 从列中获取一个热编码作为布尔值
- apache-kafka - Kafka Streams:关闭时通知流线程/任务
- eclipse - eclipse 中缺少的路径和符号(4.12、C++、Arduino)
- reactjs - Eslint 错误:多行 JSX react/jsx-wrap-multilines 周围缺少括号
- docker - 如何在命令行中限制 Docker Engine 可用的资源?
- sql - SQL SSRS 空间位置删除异常值。或仅选择前 100 名
- xml - 如何在 XML 变量中连接用户名?
- appcelerator-titanium - Appcelerator Studio 调试器忽略断点