I am trying to write a while loop to determine the number is being given to count down to 0. Also, if there's no argument given, must display "no parameters given.
Now I have it counting down but the last number is not being 0 and as it is counting down it starts with the number 1. I mush use a while loop.
My NEW SCRIPT.
if [ $# -eq "0" ] ;then
echo "No paramters given"
else
echo $#
fi
COUNT=$1
while [ $COUNT -gt 0 ] ;do
echo $COUNT
let COUNT=COUNT-1
done
echo Finished!
This is what outputs for me.
sh countdown.sh 5
1
5
4
3
2
1
Finished!
I need it to reach to 0
Your code is far from being able to run. So, I don't know where to start to explain. Let's take this small script:
The main part is the routine
seqwhich does what you need: counting from start value to end value (with increment in between). The start value is$1, the parameter to our script, the increment is -1. Thetestline tests whether there is a parameter on the command line - if not, the script ends via the subroutinedie.Hth.