我試圖測試節能啓動和關機設置通過shell只是我的字符串比較始終沒有殼字符串比較是不工作
響應這裏是我的代碼
#!/bin/sh
pmset repeat shutdown MTWRFSU 19:00:00 wakeorpoweron MTWRF 07:00:00
test=`pmset -g sched`
schd="Repeating power events: wakepoweron at 7:00AM weekdays only shutdown at 7:00PM every day"
echo $schd;
echo $test;
if [ '$test' = '$schd' ]; then
echo "yes"
else
echo "no"
fi
什麼時我在這裏做錯了嗎?
添加這是在我的測試命令的輸出作爲一切似乎是爲了預期
test2="Repeating power events: wakepoweron at 7:00AM weekdays only shutdown at 7:00PM every day"
schd2="Repeating power events: wakepoweron at 7:00AM weekdays only shutdown at 7:00PM every day"
if [ "$test2" = "$schd2" ]; then
echo "yes"
else
echo "no"
fi
我懷疑有隱藏字符,這是返回的是有一些方法來確認和根除他們,如果那實際上是問題所在?
@chepner我把它改成了雙引號,因爲我已經試過用雙引號,但仍然沒有成功,因此是的,仍然有一個問題,因爲它仍然不能用雙引號 – mcgrailm