On Mon, Jun 26, 2023, 11:07 AM Hugo Napoli <hugonap...@gmail.com> wrote:
> Good day. > > Something strange is happening to me with this script that I have designed > moments ago. > I am a Computer Science professor, and among the subjects I teach, there is > one that has to do with BASH programming. > I make my own material, therefore, I have been working since last year with > this compendium of exercises that I have created, but I had never noticed > before that the BASH output of this program could be a "bug". > If not, I apologize and I'm sorry for wasting your time. > > *This is the script code, exactly as I have it in my computer:* > > #!/bin/bash > > clear > > echo "" > read -p "Ingrese un número entero de hasta 2 cifras > : " min > read -p "Ingrese otro número entero de hasta 2 cifras, mayor que el > anterior : " max > > if [[ ${#min} -gt 2 ]] || [[ ${#max} -gt 2 ]];then > clear > echo "" && echo "Deben ser números de hasta 2 cifras..." > read -p "Pulse ENTER para continuar..." > bash "$0" > fi > > if [[ $min == $max ]];then > suma=$((min+max)) > else > for((c=$min;c<=max;c+=1)) > do > suma=$((suma+c)) > done > fi > > echo "" > echo "La suma entre "$min" y "$max", es "$suma"." > echo "" > > *This is the output when I type "222" and "222" for min and max, > respectively, and in the next try, I enter "2" and "2":* > > Ingrese un número entero de hasta 2 cifras : 2 > Ingrese otro número entero de hasta 2 cifras, mayor que el anterior : 2 > > La suma entre 2 y 2, es 4. > > > > *La suma entre 222 y 222, es 444.* > > What is in red is what I understand should not happen: the program repeats > the same operation, when the "bash $0" is supposed to reinitialize the > program and show only one result, not 2. > And if I enter 3, 4, or 5 wrong values, I get 3, 4, 5 additional results, > respectively. > > Before writing this report, I ran the same script on Arch Linux, getting > exactly the same results. > > *I'm using openSUSE 15.4 (Leap, updated until today and phisically > installed, not virtualized) with "KDE Plasma desktop 5.24.4, Frameworks > 5.90.0, Qt 5.15.2 running on X11" and kernel "5.14.21-150400.24.63-default" > and I execute all my scripts in "Konsole", now in 21.12.3 version. The > hardware is AMD Ryzen 3 3200U in an ACER Aspire 5 machine.* > > I will be at your service for whatever you need to ask me. > > Receive a warm hug from Uruguay, > > > *Hugo Napoli* > > *Espacio educativo en YouTube: > https://www.youtube.com/c/entropíabinaria > <https://www.youtube.com/c/entropíabinaria>* > *Sitio web personal: **https://hugonapoli.blogspot.com/* > <https://hugonapoli.blogspot.com/> > > *Si vas a reenviar este correo:* > *-* te agradezco que antes de hacerlo, elimines mi dirección de correo > electrónico. > *-* en lugar de poner las direcciones en el renglón "PARA", ponlas en > "CCO". De este modo, > estarás contribuyendo a que tus contactos no reciban virus y spam por > mail. > *>* Utilicemos el correo electrónico con responsabilidad. > > *Haz clic aquí para informarte en Wikipedia* > <http://es.wikipedia.org/wiki/Spam> > bash "$0" calls the script as a sub-program without any arguments. To replace the current script with a new instance use exec bash "$0"