Last active
August 29, 2015 14:07
-
-
Save h3llborn/f0c5eeaafc33c109742f to your computer and use it in GitHub Desktop.
assignment #2-q4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Author: Chris Niesel | |
# Class: Computer Science 2211A | |
# check if there are 2 arguments | |
if [ "$#" -eq "2" ] | |
then | |
# check if file doesn't exist | |
if [ ! -f "$2" ]; then | |
echo "input-file not found" | |
exit 2 | |
# check what number argument #1 is | |
# if argument #1 is equal to 1 show highest and second highest number | |
elif [ "$1" -eq 1 ] | |
then | |
echo highest=`cat "$2" | sort -n | tail -2 | awk 'NR == 2'` | |
echo secondHighest=`cat "$2" | sort -n | tail -2 | awk 'NR == 1'` | |
exit 0 | |
# if argument #1 is equal to 0 show lowest and second lowest number | |
elif [ "$1" -eq 0 ] | |
then | |
echo smallest=`cat "$2" | sort -n | head -2 | awk 'NR == 1'` | |
echo secondSmallest=`cat "$2" | sort -n | head -2 | awk 'NR == 2'` | |
exit 0 | |
# if argument #1 is not between 0 or 1 output error | |
else | |
echo "Option must be 0 or 1" | |
exit 3 | |
fi | |
else | |
# if input is less or more than 2 arguments output error and exit | |
echo "Usage: nums option input-file" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment