Expect スクリプトの Cat は、文字列の末尾に新しい行を追加します。

Expect スクリプトの Cat は、文字列の末尾に新しい行を追加します。

expect私のスクリプトには次のものがあります

spawn cat version
expect -re 5.*.*
set VERSION $expect_out(0,string)
spawn rpm --addsign dist/foo-$VERSION-1.i686.rpm

コマンドはcatバージョンを正しくインポートしていますが、新しい行を追加しているようです。なぜなら、出力は次のようになると予想しているからです。

dist/foo-5.x.x-1.i686.rpm

しかし、最初は次のエラーが発生します。

cannot access file dist/foo-5.x.x
-1.i686.rpm

expectコマンド出力に新しい行が追加されるのはなぜですかcat?これを行わないか、catコマンドの出力を変更する方法はありますか?

ベストアンサー1

TCLは、次の問題なくファイルを直接読み取ることができますspawn cat

#!/usr/bin/env expect

# open a (read) filehandle to the "version" file... (will blow up if the file
# is not found)
set fh [open version]
# and this call handily discards the newline for us, and since we only need
# a single line, the first line, we're done.
set VERSION [gets $fh]

# sanity check value read before blindly using it...
if {![regexp {^5\.[0-9]+\.[0-9]+$} $VERSION]} {
    error "version does not match 5.x.y"
}

puts "spawn rpm --addsign dist/foo-$VERSION-1.i686.rpm"

おすすめ記事