
我需要一個 shell 腳本來刪除 17:00 之前安排的所有作業,並將使用者名稱作為位置參數這就是我嘗試做的
#!/bin/bash
currentTime = ‘date + %k%M’
check_time_tu_run()
{
tempTime=$1
if
[ $tempTime -gt 000 -a $tempTime -lt 1700];
then
for i in `atq | awk '{print $1}'`;do atrm $i;done
else
echo “Action is not in the period of time”
fi
}
check_time_to_run $currentTime
答案1
- 您在 date 命令周圍使用了錯誤的引用。您使用「捲曲」單引號 (
‘...’
) 而不是反引號 (`...`
),但使用$(...)
而不是反引號。 =
變數賦值時不允許在 周圍有空格- 後面
+
不能有空格。
使用:currentTime=$( date +%k%M )
還有你的函數的名稱定義( check_time_tu_run
)
不是您的函數名稱稱呼( check_time_to_run
)
還有其他錯誤:將您的程式碼貼到https://www.shellcheck.net以獲得更多幫助。