Skip to content

Instantly share code, notes, and snippets.

@jacobwyke
Created June 26, 2018 19:09
Show Gist options
  • Save jacobwyke/e9e0146037f2e6b68c9d34fc44357bcf to your computer and use it in GitHub Desktop.
Save jacobwyke/e9e0146037f2e6b68c9d34fc44357bcf to your computer and use it in GitHub Desktop.
Question 3
#!/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