문제

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