expect下命令不能解析通配符*的问题


曾遇到这样一段代码:(Bash脚本)

1
2
3
4
5
6
7
8
9
10
11
12
#!/usr/bin/expect -f
set HOST  "192.168.102.1"
set USER  "codefor"
set PASS  "codefor"
set BOOKFILE  "/home/codefor"
 
#upload
spawn  "scp *.zip $USER@$HOST:$BOOKFILE"
expect {
     "*password*"  {send  "$PASS\r" ;}
}
expect eof;

这样的话,会报不存在*.zip的错误,即不能解析通配符*

 

在命令前加上bash -c即可。

如下:

1
2
3
4
5
6
7
8
9
10
11
12
#!/usr/bin/expect -f
set HOST  "192.168.102.1"
set USER  "codefor"
set PASS  "codefor"
set BOOKFILE  "/home/codefor"
 
#upload
spawn bash -c  "scp *.zip $USER@$HOST:$BOOKFILE"
expect {
     "*password*"  {send  "$PASS\r" ;}
}
expect eof;


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM