如何在Expect脚本中查找文件是否存在 [英] How to find if a file exists in expect script

查看:930
本文介绍了如何在Expect脚本中查找文件是否存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的期望脚本中有一个这样的语句

I have a statement inside my expect script like this

send "sed -i -e 's/$oldport/$newport/' backup.txt\r"
expect "$ "

但是,我希望首先检查backup.txt文件是否存在,如果存在,然后进行编辑.

However I wish to first check whether the file backup.txt exist and if it does, then edit it.

我该如何实现?

谢谢

推荐答案

由于Expect是Tcl的扩展,因此所有Tcl命令都可以使用:

Since expect is an extension of Tcl, all Tcl commands are available to use:

if {[file exists backup.txt]} {
    send "sed -i -e 's/$oldport/$newport/' backup.txt\r"
    expect "$ "
}

这篇关于如何在Expect脚本中查找文件是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆