我是ruby
的新手(这可能是我的第一个程序)而且我正在尝试创建一个安装pacman(包管理器)可选依赖项的脚本。
我写了这段代码
#!/usr/bin/ruby
packs=""
exit if ARGV.count==0
ARGV.each do |arg|
out=%x(LANG="C" pacman -Si #{arg})
next if out.empty?
packs+="{arg} "
lines=out.split "\n"
first=(lines[11].split ":")[1].strip
next if first == "None"
packs+="#{first} "
i=12
while lines[i][0]==" " do
packs+=(lines[i].split ":")[0].strip + " "
i++
end
end
exec ("pacman -S #{packs}")
但是当我尝试运行脚本时,我得到了这些错误:
./pacman-odep:24: syntax error, unexpected keyword_end
./pacman-odep:26: syntax error, unexpected end-of-input, expecting keyword_end
有什么问题?
编辑:
如果需要,可以使用out
变量等于此文本来测试脚本:
Repository : extra
Name : gimp
Version : 2.8.14-2
Description : GNU Image Manipulation Program
Architecture : x86_64
URL : http://www.gimp.org/
Licenses : GPL LGPL
Groups : None
Provides : None
Depends On : pygtk lcms libxpm libwmf libxmu librsvg libmng dbus-glib libexif
gegl jasper desktop-file-utils hicolor-icon-theme babl openexr
Optional Deps : gutenprint: for sophisticated printing only as gimp has built-in cups print
support
webkitgtk2: for the help browser
poppler-glib: for pdf support
alsa-lib: for MIDI event controller module
curl: for URI support
ghostscript: for postscript support
Conflicts With : gimp-devel
Replaces : None
Download Size : 11.83 MiB
Installed Size : 65.23 MiB
Packager : Tobias Powalowski <tpowa@archlinux.org>
Build Date : Fri May 8 17:48:18 2015
Validated By : MD5 Sum SHA256 Sum Signature
答案 0 :(得分:2)
当前的问题是
exec ("pacman -S {packs})
它缺少一个语音标记,应该是:
exec ("pacman -S #{packs}")
第二个问题是使用i++
。替换为i+=1
。