Skip to content

Instantly share code, notes, and snippets.

@cbdavide
Created April 13, 2016 23:47
Show Gist options
  • Save cbdavide/504a4818f54101d5cfbe740dab8ad714 to your computer and use it in GitHub Desktop.
Save cbdavide/504a4818f54101d5cfbe740dab8ad714 to your computer and use it in GitHub Desktop.
Prints even numbers, and odd numbers
#!/bin/bash
re='^-?[0-9]+([.][0-9]+)?$'
if ! [[ $2 =~ $re ]] ; then
echo "El parámetro inicial NO es un número."
exit
fi
if ! [[ $3 =~ $re ]] ; then
echo "El parámetro final NO es un número."
exit
fi
option=$1
begin=$2
((end=$3+1))
if [ $option == par ]; then
while (($begin<$end)); do
if (($begin%2==0));then
echo $begin
fi
let begin=begin+1
done
elif [ $option == impar ]; then
while (($begin<$end)); do
if (($begin%2!=0)); then
echo $begin
fi
let begin=begin+1
done
fi
if [ $option == par ]; then
while (($begin<$end)); do
if (($begin%2==0));then
echo $begin
fi
let begin=begin+1
done
elif [ $option == impar ]; then
while (($begin<$end)); do
if (($begin%2!=0)); then
echo $begin
fi
let begin=begin+1
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment