[問題] shell script 如何比字串大小
大家好:
最近在撰寫一個簡單的shell script時遇上一個有趣的問題
這隻shell script是利用bash執行的
功能很簡單:就是比較兩個字串的字典順序大小
經過man bash後得到訊息
string1 == string2
string1 = string2
True if the strings are equal. = should be used with the test
command for POSIX conformance.
string1 != string2
True if the strings are not equal.
string1 < string2
True if string1 sorts before string2 lexicographically.
string1 > string2
True if string1 sorts after string2 lexicographically.
於是我寫下類似以下的code
====
if [ "$str1" < "$str2"]; then
.....
else
....
fi
====
然而它總是在判斷上失敗,並且將 < 符號認定為 I/O redirect
請問是不是我會錯意或是使用錯誤了呢?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.232.136
推
03/07 00:30, , 1F
03/07 00:30, 1F
→
03/07 00:31, , 2F
03/07 00:31, 2F
→
03/07 00:32, , 3F
03/07 00:32, 3F
→
03/07 09:22, , 4F
03/07 09:22, 4F
→
03/07 09:22, , 5F
03/07 09:22, 5F