I'm trying to make a bash script that - takes in two inputs (and only two) - then prints out all the even numbers between the two numbers - prints out orange beside any number divisible also by 7 - prints out banana beside any number divisible also by 11 - prints out pear beside any number divisible also by 13 finally prints out a statement "what is with the fruit obsession?"
it works fine within this compiler (http://www.compileonline.com/execute_bash_online.php) but in Linux it error messages saying that $Input2 is not a recognised identifier and that there is an unexpected end of file after the last line
#!/bin/bash
read -p "Type in Two integer inputs you want evaluated, followed by [ENTER]:" Input1 Input2
if [ -z $Input1 ]; then
echo "Please enter a valid first integer"
read -r Input1 Input2
exit 1
fi
if [ -z $Input2 ];
then
echo "Please enter a valid second integer"
read Input2
fi
if [ $# -gt 2 ]; then
echo "Too many numbers have been inputted"
fi
echo "You entered: $Input1,$Input2"
echo "Here are all the even numbers between your two values:"
echo ""
# if Input 1 is larger than Input 2
while [ $((Input2)) -lt $Input1 ]; do
if [ $((Input1 % 2)) -gt 0 ];then
echo -en "$((Input1 = $Input1 - 1)) "
else
echo -en "$((Input1 = $Input1 - 2)) "
fi
if [ $((Input1 % 7)) -eq 0 ]; then
echo -en "orange "
fi
if [ $((Input1 % 11)) -eq 0 ]; then
echo -en "banana "
fi
if [ $((Input1 % 13)) -eq 0 ]; then
echo -en "pear "
fi
echo
done;
while [ $((Input1)) -lt $Input2 ]; do
if [ $((Input2 % 2)) -gt 0 ];then
echo -en "$((Input2 = $Input2 - 1)) "
else
echo -en "$((Input2 = $Input2 - 2)) "
fi
if [ $((Input2 % 7)) -eq 0 ]; then
echo -en "orange "
fi
if [ $((Input2 % 11)) -eq 0 ]; then
echo -en "banana "
fi
if [ $((Input2 % 13)) -eq 0 ]; then
echo -en "pear "
fi
echo
done;
echo "what is with the fruit obsession?"
exit 0
dos2unixto fix.echo -eisn't specified by POSIX; neither is-n, for that matter. Your much, much better option is to useprintf.