bash/snippets/sort_array.sh
2018-04-30 02:53:44 +02:00

22 lines
381 B
Bash
Executable File

#!/usr/bin/env bash
array=("a c" b f "Change" "3 5")
IFS=$'\n' sorted=($(sort <<<"${array[*]}"))
echo ""
echo "Print out array elemnts (for loop)"
echo "=================================="
for val in ${sorted[@]} ; do
echo -e "\t$val"
done
echo ""
echo "Print out array elemnts (printf)"
echo "================================"
printf "\t%s\n" "${sorted[@]}"
echo ""
exit