Bash Shell loop - Help !

Dear all Linux lover,

I am a new learner to Bash Shell script and I would like to writing a script to to repeat my script.
This mean I would like to have multiple same of result after running the .sh.

#######

TIMES_NO=0
echo -n "Please enter the number for times to repeat ?"
read TIMES_NO

######

When I start the program, it will prompt for enter the number for the TIMES_NO, after I enter a number, how to writing script to loop all my script inside the sh for the multiple times ?
$TIMES_NO

I have already searching for 10+ hours but failed to do...
Would you kindly help ?:frowning:
many many thanks

Rocky

Please use code tags as required by forum rules!

man bash :

1 Like

Dear Rudic, thank you for your quick help, but I am not success to write correct script to do this, would you kindly take a look ?
My script in screen capture
www pbasehk com/stephen/temp/screen1
www pbasehk com/stephen/temp/screen2
Result
www pbasehk com/stephen/temp/result

thanks again for your help
I am so sorry the forum rules not allow to post the URL from my account..

Please, don't post screen shots/pictures, as they can't be used for further analysis. Post code or result lines within code tags.

for (( i=W_NO; i>=W_NO; i--)) will execute exactly zero times, as the ending condition is immediatedly met. You may have had i>=0 in mind?

1 Like

I have to writing a script, when run it, prompt for width and height value, enter both value and then used to created a drawing pattern on the screen...

my current script is actually copy from another sample used create a triangle pattern...
I modify the value and hopes it can being a rectangle....

on your mentions script, it will execute 1 time and show one row on the screen, so I hopes to made it become multiple....thanks

---------- Post updated at 11:04 AM ---------- Previous update was at 11:02 AM ----------

or do you have any suggestion I can write a script to do that ?

Are you looking for something basic as:

printf "Please enter the number of loops: "
read number

C=0
while [ "$C" -lt "$number" ]
do	echo "Loop nr: $C"
	((C++))
done

Place your code inside the loop.

hth

I have tried to enter the code with my code
after I enter the number of loops
result show

Loop nr: 0
Loop nr: 1
Loop nr: 2
Loop nr: 3

please kindly help me, thank you so much

Run this and see if it does help you to understand.

#!/bin/bash

height=4
width=8

for ((i=0; i<height; i++)); do
    for((j=0; j<width; j++)); do
        printf "*"
    done
    echo
done
1 Like

So - this is exactly what is to be expected, and what you said you need. What do you think is missing? Please post details: code, expected output, description of problems.

1 Like

Actualy its not, i had not set (init) the variable "properly"...

C=1

Might help.

For the memory:

Or, are you confused because i named the TIMES_NO as C ?

1 Like

yes, after mixed all your answer and I study, modify again, it's finally done !
would like to say thank you again to Rudic, Sea and Aia !
I am feeling warm for all your help :slight_smile: