Posted By

Hexx on 12/01/10


Tagged

sort Bash


Versions (?)

Simple Bash Sort Script


 / Published in: Bash
 

URL: http://www.amugofjava.me.uk/

Simple bash script that sorts a series of numeric parameters using a temporary file and sort command.

  1. #!/bin/sh
  2. # Simple Sort Script By Ben
  3. for f in $@
  4. do
  5. # Store parameters in temp file
  6. echo $f >> sortme.tmp
  7. done
  8. # Sort temp file
  9. for f in `cat sortme.tmp | sort -n`
  10. do
  11. f2="$f2 $f"
  12. done
  13.  
  14. # Delete temp file
  15. rm sortme.tmp
  16.  
  17. # Show output
  18. echo $f2

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: Hexx on December 1, 2010

Example:

./sort.sh 5 8 10 2 5 4 7

Gives the result

2 4 5 5 7 8 10

You need to login to post a comment.