Would you please show me know how I can sort the following list (ascending oder A to Z) (or a list in general) with Bash?
I have been trying but still could not get the expected results:
my_list='a z t b e c'
And the result should be a list as well, as I will use it for Select Loop.
my_list='a b c e t z'
Thanks for your help!
You can use xargs twice along with a built in sort
command to accomplish this.
$ my_list='a z t b e c'
$ my_list=$(echo $my_list | xargs -n1 | sort | xargs)
$ echo $my_list
a b c e t z
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