It seems that the built-in 'test' does not work properly when run
in a sub-shell.
Repeat-By:
Under Windows 10, WSL.
Start "bash", terminal with shell pops up.
1. This works when typed directly:
# make everything explicit
export PATH=""
# ensure that file1 exists and that file2 does not exist
/bin/touch file1
/bin/rm -f file2
# built-in
if [ file1 -nt file2 ]; then echo nt; else echo not_nt; fi
# external
if /usr/bin/[ file1 -nt file2 ]; then echo nt; else echo not_nt; fi
# Output is as expected:
nt
nt
2. This does not work:
# Put the above commands into a script, say check.sh
# Run with: /bin/sh < check.sh
# Or : /bin/sh ./check.sh
# Or : /usr/bin/env ./check.sh
# Output is always not ok:
not_nt
nt