What I have put in the title. It's like something introductory, I have this, the problem I have is that when I run the script, if the parameter is not included between 1 and 100 or the parameter is not passed, it shows an error message and the way to do it correctly .
I'll pass you the code I have so far.
I hope you can give me a hand, thanks.
#!/bin/bash
MAYOR=100
CONTADOR=1
echo "Introduce un valor"
if [ $1 -gt $MAYOR ]
then
echo "Error, insertar número del 1 a 100"
fi
echo "Introduzca de nuevo su valor"
while [ $CONTADOR -lt $1 ]
do
echo "Número $CONTADOR"
let CONTADOR=CONTADOR+1
done
if [ $1 -le $MAYOR ]
then
echo "Número $CONTADOR"
fi
The output my code gives:
./script.sh 4
Numero 1
Numero 2
Numero 3
Numero 4
The problem is that when I put more than 100 I don't get the error message and it keeps counting from number 1 to a number greater than 100 (parameter inserted at the beginning of the script).
If I understand correctly your question should be something like this:
If the appropriate value was not entered as a parameter, we ask it, for that we use
read
and ask it inside a loopuntil
until the value meets the requirements.Once they are fulfilled, we go to the next step, which from what I see is to decrease it.
I hope it helps you ;-)
Just keep an infinite loop that you exit when the valid value insert occurs.
Then, use
seq
to generate the list of numbers, no need to create it by hand :)