【发布时间】:2017-09-08 22:24:52
【问题描述】:
我正在尝试从 ifconfig 命令解析 IP 地址。当我在命令行上执行此操作时,它工作正常
pb791b@pb791b-VirtualBox:~/devtest/ngs/base/Tests/shellScripts$ ifconfig enp0s3 | sed -n '/inet addr/s/.*addr.\([^ ]*\) .*/\1/p'
192.168.1.112
但是当我在期望脚本中使用它时会出错。
#!/usr/bin/expect
set pidBash [ spawn bash ]
set ipIfConfig {ifconfig enp0s3 | sed -n '/inet addr/s/.*addr.\([^ ]*\) .*/\1/p'}
set clientIP [exec "echo $ipIfConfig"]
puts "clientIP = $clientIP"
exit 1
输出是
pb791b@pb791b-VirtualBox:~/devtest/ngs/base/Tests/shellScripts$ ./ifconfig_parse.sh
spawn bash
couldn't execute "echo ifconfig enp0s3 | sed -n '/inet addr/s/.*addr.\([^ ]*\) .*/\1/p'": no such file or directory
while executing
"exec "echo $ipIfConfig""
invoked from within
"set clientIP [exec "echo $ipIfConfig"]"
(file "./ifconfig_parse.sh" line 7)
【问题讨论】:
-
this question 有帮助吗?
-
试试“bash ifconfig_parse.sh”