該文件夾中的文件清單郵編全部用相同後綴的文件:Linux系統:使用expect腳本
$ LL * TXT
-rw-rw-rw- 1 psawant CVS_GROUP 32 Mar 25 13:34 File.txt
-rw-rw-rw- 1 psawant CVS_GROUP 51 Mar 25 13:34 File_Changes.txt
-rw-rw-rw- 1 psawant CVS_GROUP 29 Mar 25 13:35 file1.txt
-rw-rw-rw- 1 psawant CVS_GROUP 29 Mar 25 13:35 file2.txt
-rw-rw-rw- 1 psawant CVS_GROUP 29 Mar 25 13:35 file3.txt
Expect腳本焦油具有固定名稱的文件和所有其他文件前綴 「文件」:
$貓tar.exp
#!/usr/bin/expect -f
set timeout -1
match_max 100000
set PWD "12345"
set FILE1 "File.txt"
set FILE2 "File_Changes.txt"
spawn zip -e -j ZIP.zip $FILE1 $FILE2 file*
expect "Enter password:"
sleep 1
send -- "$PWD\r"
sleep 1
expect "Verify password:"
sleep 1
send -- "$PWD\r"
sleep 3
interact
當我從腳本運行它時,它將文件*視爲文件名,但是當我使用相同的spawn命令並直接運行它時,它可以工作。
$ tar.exp
spawn zip -e -j ZIP.zip File.txt File_Changes.txt file*
Enter password:
Verify password:
zip warning: name not matched: file*
updating: File.txt (deflated 16%)
updating: File_Changes.txt (deflated 35%)
$ zip -e -j ZIP.zip File.txt File_Changes.txt file*
Enter password:
Verify password:
updating: File.txt (deflated 16%)
updating: File_Changes.txt (deflated 35%)
adding: file1.txt (deflated 24%)
adding: file2.txt (deflated 24%)
adding: file3.txt (deflated 24%)
怎樣才能使它從script.What變化,我需要做才能使它這種變化工作?
什麼不使用while循環並迭代文件? – Ajit 2015-03-25 06:50:33
由於文件不一定與連續編號。它可以是任何東西 - file2567.txt或file31456.txt – 2015-03-25 06:55:02
Ohk。似乎不支持通配符。嘗試在腳本中使用set + f來啓用通配符。 – Ajit 2015-03-25 07:13:51