I am trying to sort all values of a list and add them, sorted, into another list . The sort -nu works fine but he doesn't want to add $i to the new SortedList. What could be the problem here?
function Sort() {
SortedList=""
for i in $list;
do
echo $i
$SortedList= "$SortedList $i"
done | sort -nu
}
echo " This is the sorted list : $SortedList"
I think you can do something like the following.
#!/bin/bash
list="7 4 2 5 3"
function Sort() {
SortedList=$(echo $list | tr " " "\n" | sort -nu)
}
Sort
echo $SortedList
It may fail because we still don't know how your list
looks like.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With