我是新的ruby
(這也許是我的第一個程序),我試圖做一個安裝pacman(包管理器)可選依賴的腳本。 我已經寫代碼語法錯誤,意外的keyword_end
#!/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 <[email protected]>
Build Date : Fri May 8 17:48:18 2015
Validated By : MD5 Sum SHA256 Sum Signature
其中兩個錯誤與最後一行中的不匹配雙引號相關。 –
不要編輯問題以改變其意義。編輯錯誤會使問題和任何現有的答案變得毫無意義。我已回滾您的更改。 –
@HoboSapiens可能付出還原早期的變化以及 – Rots