Shell 为什么我的if/else语句不';不行?(壳牌)

Shell 为什么我的if/else语句不';不行?(壳牌),shell,Shell,我对这个shell脚本有问题: current_time=$(date +"%T"); current_day_of_week="$(date +'%u')"; if [[ current_day_of_week == 1 ]]; then echo "Setting max time to 03:00:00" && max_time="03:00:00"; else echo "S

我对这个shell脚本有问题:

current_time=$(date +"%T"); 
current_day_of_week="$(date +'%u')"; 
if [[ current_day_of_week == 1 ]]; 
then echo "Setting max time to 03:00:00" && max_time="03:00:00"; 
else echo "Setting max time to 01:30:00" && max_time="01:30:00"; fi; 
我想在星期一时将变量
max\u time
设置为
03:00:00
,但代码不起作用:(

字符串“current\u day\u of_week”与字符串“1”不同。如果要比较变量的值,需要取消引用它。替换

if [[ current_day_of_week == 1 ]];

由于没有出现语法错误,我们可以假设您使用的是支持
[[
语法的
shell
(您可能应该更改标记!),因此您可以使用:

if [[ $current_day_of_week == 1 ]];
请注意,尽管在
[[
构造中引用变量不是绝对必要的,但还是最好使用引号:

if [[ "$current_day_of_week" == 1 ]];

啊,是的,谢谢你!
if [[ "$current_day_of_week" == 1 ]];