Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Shell 使用_Shell_Date_Unix_Datetime_Unix Timestamp - Fatal编程技术网

Shell 使用

Shell 使用,shell,date,unix,datetime,unix-timestamp,Shell,Date,Unix,Datetime,Unix Timestamp,我努力解决问题,然后在上面提供帮助 T=`date + %k` if [ $t –ge 0 –a $t –le 12 ]; then echo “Good Morning” elif[ $t –ge 12 –a $t –le 14 ]; then echo “Good Afternoon” elif[ $t –ge 14 –a $t –le 18 ]; then echo “Good Evening" else echo “Good night” fi 输出:[

我努力解决问题,然后在上面提供帮助

T=`date + %k`
if [ $t –ge 0 –a $t –le 12 ];
then
    echo “Good Morning”
elif[ $t –ge 12 –a $t –le 14 ];
then
    echo “Good Afternoon”
elif[ $t –ge 14 –a $t –le 18 ];
then
    echo “Good Evening"
else
    echo “Good night”
fi

输出:[:日期意外运算符

(1)您的T应该是相同的大小写(您分配
T
,但使用
$T
)。(2)您必须在
elif
[
。是的,但错误在那之前就出现了。它必须是
日期+%k
,在
+
%k
@mjsqu之间没有空格。这就是为什么我给出了一个评论,而不是答案。我引用的是问题。而且,那些破折号看起来很长,你是从MS Word或其他文字处理应用程序复制的吗?破折号必须是-。此外,双引号不是纯双引号。
t=`date +%k`
if [ $t -ge 0 -a $t -le 12 ];
then
  echo "Good Morning"
elif [ $t -ge 12 -a $t -le 14 ];
then
  echo "Good Afternoon"
elif [ $t -ge 14 -a $t -le 18 ];
then
  echo "Good Evening"
else
  echo "Goodnight"
fi