Pergunta

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
Foi útil?

Solução

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.
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top