I'm trying to alphabetize three strings and then concatenate them together. So for example if I have:
a="zebra"
b="ape"
c="fox"
I should end up with apefoxzebra
I need to do with WITHOUT using sort.
Here's what Ive been trying to alphabetize the strings, but it doesn't seem to be sorting right. It just picks 'a' every time.
a="zebra"
b="aardvark"
c="cat"
if [[ "$a" -le "$b" && "$a" -le "$c" ]]; then
first=$a
elif [[ "$b" -le "$a" && "$b" -le "$c" ]]; then
first=$b
else
first=$c
fi
Thanks to @gniourf_gniourf for the answer!
-le
is for arithmetic comparison. To compare strings lexicographically, use<
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.