Hi All,
I want to execute a script the number of times a user enters. Please can you advise on hor can I do the same.
Many Thanks,
Shazin
Hi All,
I want to execute a script the number of times a user enters. Please can you advise on hor can I do the same.
Many Thanks,
Shazin
one way
# cat loop
#!/bin/bash
x=0
while [ $x -lt $1 ]
do
x=$(($x+1))
echo loop $x # i.e. replace this line with whatever your wanting...
done
# ./loop 4
loop 1
loop 2
loop 3
loop 4
HTH
Hies,
Many thanks for the same. Please can you also advise were can I take an input from the user for giving an option on how many times he requires for the loop to execute.
Best Regards,
Shazin
---------- Post updated at 02:11 PM ---------- Previous update was at 01:44 PM ----------
Hies,
Got the logic, many thanks but please can you advise if this cannot be done with the for loop.
Cheers,
Shazin
---------- Post updated at 02:15 PM ---------- Previous update was at 02:11 PM ----------
Hies,
Many thanks. Also this can be done by th ebelow code without giving the command line argument.
#!/bin/ksh
read value
x=0
while [ $x -lt $value ]
do
x=$(($x+1))
echo loop $x # i.e. replace this line with whatever your wanting...
done
Cheers,
Shazin
small change then:
i#!/bin/bash
echo how may times?
read y
x=0
while [ $x -lt $y ]
do
x=$(($x+1))
echo loop $x # i.e. replace this line with whatever your wanting...
done
HTH
Or both, if not argument, then ask
y="$1"
if [ "$y" = "" ] ; then
echo -n ".... ?"
read y
fi
...