As Rafe points out in the other answer, -eq
is numeric, you need to use ==
to compare strings. But you said that you want to tell if the time is between two times, not exactly equal to one. In that case you should use the <
operator:
if [ '08:03' \< "$dt" -a "$dt" \< '14:03']
Or more conveniently:
if [[ '08:03' < "$dt" && "$dt" < '14:03']]
Note that these operators are not specified in POSIX, but work on most shells (Bash, Korn Shell, zsh). Just beware of using them if you're using a minimal shell like Dash (which is what /bin/sh
is on Ubuntu).