Uri D. Charles
Uri D. Charles

Reputation: 57

Sorting characters without using the sort in unix

Hey so I'm extremely new to unix, and I grasp the basics, but I'm stuck at this one part.

So I'm to input values (letters) and sort them, without using the sort method. I considered changing the values of the letters to ACSII values and using if statements in that manner.

Is this the right way to go about this? I know this is how you do it for numbers

echo Enter 2  numbers with spaces in between
read a b 
l=$a
if [ $b -gt $l ]
then
l=$b
fi
echo Largest of $a $b is $l

so I'm ASSUMING converting them to values would make sense. I know in java I would do something similar. Again, I'm pretty new.

Upvotes: 1

Views: 1088

Answers (1)

Thomas Dickey
Thomas Dickey

Reputation: 54505

test, e.g., "[" and "]" assumes the operands are integers, which does not sound like what you want. expr can sort letters, using syntax like

if expr $b \> $l

I ran into an amusing problem with a shell which confused the two - see my notes

Upvotes: 2

Related Questions