what is the wrong?
#!/usr/local/bin/bash
REF_FILE_NUM="000000010000001900000052"
for id in `ls -1 dir` ;
do
FILE_NUM=${id:0:24}
echo "FILE_NUM: $FILE_NUM ; REF_FILE_NUM: $REF_FILE_NUM"
if [[ "$FILE_NUM" < "$REF_FILE_NUM" ]]
then
echo "$FILE_NUM lt $REF_FILE_NUM"
echo ""
else
echo "$FILE_NUM gt $REF_FILE_NUM"
echo ""
fi
done
freebsd# ./test.sh
FILE_NUM: 0000000100000019000000FF ; REF_FILE_NUM: 000000010000001900000052
0000000100000019000000FF gt 000000010000001900000052
FILE_NUM: 0000000100000020000000FF ; REF_FILE_NUM: 000000010000001900000052
0000000100000020000000FF gt 000000010000001900000052
FILE_NUM: 0000000100000021000000FF ; REF_FILE_NUM: 000000010000001900000052
0000000100000021000000FF gt 000000010000001900000052
20
and21
are greater than19
. (1) Please explain what the script is supposed to be doing. (2) Please tell us what your filenames are. (Do this explicitly, separately from the output of your script.) (3) Explain what output you expect, and why. (4) Explain why you believe that the actual output is wrong. (5) Your filenames have a lot of zeroes in them, and are hard to read. Repeat your test with short names like11952
,119FF
,120FF
and121FF
. … Please do not respond in comments; edit your question to make it clearer and more complete. – Scott Jul 19 '19 at 14:28