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

我在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

来源: https://codeday.me/bug/20190814/1650989.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值