expect中使用exec执行shell命令

今天想在expect脚本中获取本机ip,执行脚本是报错,脚本如下:

set localip [exec ifconfig eth0 | grep Mask | cut -d: -f2 | awk '{print $1}]

solution :exec sh -c {your commands here}

 获取ip的脚本可以写成:

set idcid [exec sh -c {ifconfig eth0 | grep Mask | cut -d: -f2 | awk '{print $1}'}]


参考资料:

1. http://www.linuxquestions.org/questions/linux-software-2/ksh-tcl-173092/

2. http://blog.csdn.net/bonny95/article/details/5786283

3. http://wiki.tcl.tk/1039

原文地址:https://www.cnblogs.com/likai198981/p/3706875.html