在linux下寫了一個簡單的shell,循環10次.
test.sh
#!/bin/bash ## ##循環10次 ## for ((i=0; i<10; i++)); do echo Good Morning ,this is $i shell program. done
執行:sh test.sh 報下面的錯誤.
Syntax error: Bad for loop variable
在網上搜索了一下.
因為Ubuntu為了加快開機速度,用dash代替了傳統的bash,所以我們這樣執行就沒問題.
bash test.sh
那如果我們只想用sh test.sh 這樣的方式執行,怎么辦呢?
修改一下代碼.
for i in `seq 10` do echo Good Morning ,this is $i shell program. done
這個時候,你再執行 sh test.sh,就不會報錯誤啦.
