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
            Asked
            
        
        
            Active
            
        
            Viewed 4,661 times
        
    0
            
            
        - 
                    http://stackoverflow.com/search?q=sort+bash+array – givanse Dec 28 '13 at 06:50
- 
                    Can the input be given in a file, or should it be in a bash variable? – Håkon Hægland Dec 28 '13 at 08:42
1 Answers
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
 
    