Executing [ FILE1 -ot FILE2 ] yields different results in make and shell

前端 未结 1 844
一生所求
一生所求 2021-01-28 04:59

From Table 7-1 of Bash Guide for Beginners, we can say that [ FILE1 -ot FILE2 ] will yield True if FILE1 is older than FILE2, or

相关标签:
1条回答
  • 2021-01-28 05:32

    Try this experiment (in a script):

    In the case I tested: when file1 does not exist and when file2 does exist:

    #!/bin/sh
    
    [ file1 -ot file2 ] && echo "file1 older" || echo "file2 older"
    

    yields file2 older

    #!/bin/bash
    
    [ file1 -ot file2 ] && echo "file1 older" || echo "file2 older"
    

    yields file1 older

    By default make will use #!/bin/sh as the shell, you can change this by: SHELL = /bin/bash in your makefile

    I am not sure why this is different - its just a different implementation between sh and bash...

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