2014-03-14 80 views
1

我做了一個調用jvm來執行jar程序的bash腳本。該腳本運作良好。我想用PROG'爲」在一段時間內執行我的bash腳本,但腳本只適用部分:使用'at'來執行bash腳本

#!/bin/bash 

touch hello.world 
while read line 
do 
    touch another.hello.world 
    name=$line 
... 
done < "https://stackoverflow.com/users/me/readin.txt" 

我所使用的命令:

$ at -f myscript.bash now 

只有hello.world文件生成,但沒有another.hello.world。所以,我的腳本或命令的用法一定有問題。我該怎麼辦?

+2

你爲什麼覺得有什麼問題? 'at'腳本沒有標準輸入,所以'while read'循環內部沒有任何內容運行;除非您從文件重定向 - 如果您重定向循環的輸入,則沒有輸入可以迭代,您在此處給出的示例不會顯示它。 –

+1

它適合我。 'readin.txt'的內容是什麼? –

+0

@DigitalTrauma僅僅包含多行文字,由\ t分割。這個腳本曾經在另一個linux盒子上工作過,但現在它不起作用。 – user3366245

回答

0

another.hello.world文件未被創建的唯一可能性是while循環的迭代至少沒有發生一次。

可能輸入文件/users/me/readin.txt爲空。

我建議你用set -x選項執行代碼,你會發現原因。它將顯示正在執行的內容。

#!/bin/bash 

touch hello.world 
set -x 
while read line 
do 
    touch another.hello.world 
    name=$line 
... 
done < "https://stackoverflow.com/users/me/readin.txt" 
set +x