shell script to run x times

Hi,

First i need to cd to this directory $SWDIR/util
Second i need to run the following either 4 times or 20 times

./swadm add_process 1 BG Y

how can i put this in a script

Thanks,

lookinginfo wrote:
> First i need to cd to this directory $SWDIR/util
> Second i need to run the following either 4 times or 20 times
>
> ./swadm add_process 1 BG Y
>
> how can i put this in a script

is this a school assignment?


palladium

can i put this in a script

Yes.

How: See Linux Command Org. Read the excellent site or read the authors book. It’s GPL.

Hi,

lookinginfo <lookinginfo@no-mx.forums.opensuse.org> writes:

> Hi,
>
> First i need to cd to this directory $SWDIR/util
> Second i need to run the following either 4 times or 20 times
>
> ./swadm add_process 1 BG Y
>
> how can i put this in a script
>
> Thanks,

Am I correct in thinking you are asking how to write a for loop?


Regards,
Barry Nichols

opensuseforumorg42 wrote:

>
> <QUOTE>how can i put this in a script<\QUOTE>
>
> Yes.
>
> See ‘Linux Command Org’
> (http://www.linuxcommand.org/writing_shell_scripts.php). Read the
> excellent site or read the authors book. It’s GPL.
>
>
Or you can invoke “man bash” from the console or you can open konqueror and
put

#bash

in the adress field to see the man page nicely formatted and look for the
“for” construct.

This looks like some good information! Thanks!

Look for the “if” statement and the “for” statement. Not working example with some blocks which could help:


# Change directory
cd $SWDIR/util

# Set the variable n, which should store the number of iterations,
# either to 4 when condition "bla_bla" or else to 20
if bla_bla then
  n=4
else
  n=20
fi

# loop n times and do something in that loop
# (initialize the variable i with 1, then loop as long as i is
# smaller than or equal the variable n. increase i by 1 on
# every looping)
for (( i=1; i<=$n; i++ ))
do
  ./swadm add_process 1 BG Y
done