Question

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
Was it helpful?

Solution

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.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top