#!/bin/sh -u # read three integers and sort them #------------------------------------------------------------------ # Syntax: $0 (No command line arguments used.) #------------------------------------------------------------------ # Purpose: # Prompt the user to enter three integers (all on the same line). # Put the integers on separate lines; sort them; put them back on one # line again. Display the sorted result. #------------------------------------------------------------------ # -Ian! idallen@idallen.ca # Use standard search path, friendly umask, ASCII collating and sorting. # Set the language and character set to be ASCII/C standard. # PATH=/bin:/usr/bin ; export PATH LC_COLLATE=C ; export LC_COLLATE LANG=C ; export LANG umask 022 echo 1>&2 "$0: Enter three or more integers separated by blanks:" read numbers # split into lines; sort; replace newlines by spaces # str=$( echo "$numbers" | tr ' ' '\n' | sort -n | tr '\n' ' ' ) # pick off first three integers and assign to variables # n1=$( echo "$str" | awk '{print $1}' ) n2=$( echo "$str" | awk '{print $2}' ) n3=$( echo "$str" | awk '{print $3}' ) # display the result # echo "The first three integers sorted are $n1 and $n2 and $n3."