ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

linux – cat in expect脚本在字符串结尾添加新行

2019-08-14 06:51:24  阅读:20  来源: 互联网

标签:cat expect linux output newlines



我在expect脚本中有以下内容

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

cat命令正确获取版本,但它似乎是添加一个新行.因为我希望输出如下:

DIST /富-5.x.x-1.i686.rpm

但是我开始在下面开始包含错误:

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

为什么期望在cat命令输出中添加一个新行,是否有任何方法可以不执行此操作或修复cat命令的输出?

解决方法:

TCL可以直接读取文件,而不会产生spawn的复杂性:

#!/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"


标签:cat,expect,linux,output,newlines

专注分享技术,共同学习,共同进步。

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有