-
-
Save jacobwyke/e9e0146037f2e6b68c9d34fc44357bcf to your computer and use it in GitHub Desktop.
Question 3
This file contains hidden or 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/bash | |
# Run a bunch of checks on the data entered | |
if [ "$#" -lt 2 ] || [ "$#" -gt 2 ] | |
then | |
echo "Usage '$0 <starting number> <ending number>'"; | |
exit; | |
fi | |
if [ $1 -lt 0 ] | |
then | |
echo "The starting number must be >=0."; | |
exit; | |
fi | |
if [ $2 -gt 100000 ] | |
then | |
echo "The ending number must be <=100000."; | |
exit; | |
fi | |
if [ $2 -lt $1 ] | |
then | |
echo "The starting number must be less than the ending number."; | |
exit; | |
fi | |
# Prepare for output | |
echo -n "["; | |
# Loop through the numbers and echo the odd ones | |
for i in $(seq $1 $2) | |
do | |
if [ $(( i % 2)) -ne 0 ] | |
then | |
echo -n " $i"; | |
fi | |
done | |
# Close final output | |
echo " ]"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment