Anonymous user
Sort an integer array: Difference between revisions
→{{header|UNIX Shell}}: corrected to printing $sorted instead of $nums
(→{{header|UNIX Shell}}: corrected to printing $sorted instead of $nums) |
|||
Line 1,217:
<lang bash>nums="2 4 3 1 5"
sorted=`printf "%s\n" $nums | sort -n`
echo $
Alternate solution: <tt>sorted=`for i in $nums; do echo $i; done | sort -n`</tt>
Line 1,227:
<lang bash>set -A nums 2 4 3 1 5
set -A sorted $(printf "%s\n" ${nums[*]} | sort -n)
echo ${
Users of [[bash]], [[ksh93]] and [[mksh]] can probably use the <tt>nums=(2 4 3 1 2)</tt> syntax.
|