有什么问题吗?
#!/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
答案1
这一切都归结为
[[ F > 5 ]] && [[ 2 > 1 ]]
在 ASCII 中,F
是 70 (0x46),而5
是 53 (0x35)。
您期望什么输出以及为什么?