Why is my string comparison in Bash always evaluated as true?

前端 未结 2 566
广开言路
广开言路 2021-01-18 00:32

I have a script checking if a file is up-to-minute.

updatedate=`ls -l file | sed -e \'s/  */ /g\' | cut -d\' \' -f7` #cut the modification time
nowdate=`date         


        
相关标签:
2条回答
  • 2021-01-18 01:20

    You need a space on each side of the equals sign.

    
    if [ "$updatedate" = "$nowdate" ]
    
    0 讨论(0)
  • 2021-01-18 01:22

    You need to separate all the arguments to test with whitespace. As it stands you have = right up against its two operands so test sees one argument, not the three that you intend.

    0 讨论(0)
提交回复
热议问题