I am getting error "syntax error near unexpected token `if'" while executing the shell script.

Could someone help me find out if I am doing some mistake syntactically.

if [ date "+%b %d" == ls -lrt start.log | tr -s " " | cut -d" " -f6-7 ] &&
   [ date "+%k" == ls -lrt start.log | tr -s " " | cut -d" " -f8 | cut -c1-2 ] &&
   [ ls -lrt start.log | tr -s " " | cut -d" " -f8 | cut -c4-5 >= date -d "now 15 minutes ago" "+%M" ]; then
有帮助吗?

解决方案

You need to use command substitutions to capture the output of the commands for comparison.

if [ $(date "+%b %d") = $(ls -lrt start.log | tr -s " " | cut -d" " -f6-7) ] &&
    # etc.
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top