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