How can I take sort bash arguments alphabetically?
$ ./script.sh bbb aaa ddd ccc
and put it into an array such that I now have an array {aaa, bbb, ccc, ddd}
You can do:
A=( $(sort <(printf "%s\n" "$@")) )
printf "%s\n" "${A[@]}"
aaa
bbb
ccc
ddd
It is using steps:
arguments list i.e.
"$@"`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