我有以下代码,用于迭代宝石列表并使用gem install $gem
安装每个宝石。但是,当gem名称包含连字符/破折号时,脚本会将连字符两侧的单词视为两个单独的列表项。如何正确地转义连字符,以便列表将其视为一个项目?
# Install gems for all installed versions of ruby
source /usr/local/share/chruby/chruby.sh
gems=(
"bundler"
"homesick"
"mechanize"
"vagrant"
"gist"
"pry"
"awesome_print"
"overcommit"
"rubocop"
"jshint"
"gem-release"
"aws"
"librarian-chef"
"knife-solo"
)
rubies=`chruby`
for ruby in ${rubies[@]}
do
IN="$ruby"
set -- "$IN"
IFS="-"; declare -a Array=($*)
echo "Installing gems for ${Array[1]}"
chruby ${Array[1]}
echo `ruby -v`
for gem in ${gems[@]}
do
echo $gem
if ! gem list $gem -i > /dev/null 2>&1
then
gem install $gem
fi
done
done
我尝试过的事情:
\e-
-*
gem\055name
最后一个示例适用于echo
,但不适用于gem install "$gem"
。
我可以做些什么来完成这项工作?