0

I need to write sorting code array function in bash and first input is number of number and end return array sorted for example :: input 5 2 4 10 1 4returns 1 2 4 4 10

codeforester
  • 39,467
  • 16
  • 112
  • 140
user3141340
  • 1
  • 1
  • 1

1 Answers1

2

The following script sorts array a where first element in the array is the number of elements in the array. The result is stored in variable b

#! /bin/bash

IFS=$'\n' a=( 3 3 2 1 )
b=$(sort <<< "${a[*]:1}")
echo ${b[*]}
Håkon Hægland
  • 39,012
  • 21
  • 81
  • 174