|
Home > Archive > Unix Programming > February 2004 > Help - a question on Unix/Linux script
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Help - a question on Unix/Linux script
|
|
|
| Hi,
This is a newbi question on Unix/Linux script. Your help would be
appreciated.
I need to run a utility (#./my_util -p some_value) for 10 times, and each
time a different value increased by 1 needs to be passed to the utility.
The simple script to run my_util 10 times with the same parameter (-p 100)
may look like this:
for 1 2 3 4 5 6 7 8 9 10
do
../my_util -p 100
done
The question is how I can use a different value (from 100 to 109) for each
instance of my_util in the script?
Thanks,
T.
| |
| Måns Rullgård 2004-02-25, 12:34 pm |
| "L" <L_X2828@yahoo.com> writes:
> Hi,
>
> This is a newbi question on Unix/Linux script. Your help would be
> appreciated.
>
> I need to run a utility (#./my_util -p some_value) for 10 times, and each
> time a different value increased by 1 needs to be passed to the utility.
>
> The simple script to run my_util 10 times with the same parameter (-p 100)
> may look like this:
>
> for 1 2 3 4 5 6 7 8 9 10
> do
> ./my_util -p 100
> done
>
> The question is how I can use a different value (from 100 to 109) for each
> instance of my_util in the script?
for i in 100 101 102 ...
do
./my_util -p $i
done
--
Måns Rullgård
mru@kth.se
| |
| Jens.Toerring@physik.fu-berlin.de 2004-02-25, 12:34 pm |
| In comp.unix.programmer L <L_X2828@yahoo.com> wrote:
> I need to run a utility (#./my_util -p some_value) for 10 times, and each
> time a different value increased by 1 needs to be passed to the utility.
> The simple script to run my_util 10 times with the same parameter (-p 100)
> may look like this:
> for 1 2 3 4 5 6 7 8 9 10
> do
> ./my_util -p 100
> done
> The question is how I can use a different value (from 100 to 109) for each
> instance of my_util in the script?
Well, the simplest way (in bash etc.) would be
for i in 100 101 102 103 104 105 106 107 108 109; do
./my_util -p $i;
done
Of course, there are more fancy ways like
i=100;
while [ $i -lt 110 ]; do
./my_util -p $i;
let i+=1;
done
Regards, Jens
--
\ Jens Thoms Toerring ___ Jens.Toerring@physik.fu-berlin.de
\__________________________ http://www.toerring.de
| |
|
| Thanks so much.
my_util runs for 10 sec once starts. Since I need to run 10 instances of
my_util concurrently (not one by one), so I create a script (go_client)
using & like this:
for i in 100 101 102 103 104 105 106 107 108 109;
do
./my_util -p $i &;
done
When invoking this script, I got error msgs:
../go_client: line 3: syntax error near unexpected token ';'
../go_client: line 3: './mu_util -p $i &;'
What do I miss?
Thanks,
T.
| |
| Lorinczy Zsigmond / Domonyik Mariann 2004-02-25, 1:34 pm |
|
L wrote:
>
> Thanks so much.
>
> my_util runs for 10 sec once starts. Since I need to run 10 instances of
> my_util concurrently (not one by one), so I create a script (go_client)
> using & like this:
>
> for i in 100 101 102 103 104 105 106 107 108 109;
> do
> ./my_util -p $i &;
> done
>
> When invoking this script, I got error msgs:
> ./go_client: line 3: syntax error near unexpected token ';'
> ./go_client: line 3: './mu_util -p $i &;'
>
> What do I miss?
remove ';' from the end of line 3
| |
| Michael Heiming 2004-02-25, 4:34 pm |
| -----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
L <L_X2828@yahoo.com> wrote:
[..]
> I need to run a utility (#./my_util -p some_value) for 10 times, and each
> time a different value increased by 1 needs to be passed to the utility.
[..]
> for 1 2 3 4 5 6 7 8 9 10
> do
> ./my_util -p 100
> done
> The question is how I can use a different value (from 100 to 109) for each
> instance of my_util in the script?
for i in `seq 100 109`;do ./my_util -p $i;done
Hint:
man seq
Good luck
- --
Michael Heiming - RHCE (GPG-Key ID: 0xEDD27B94)
Remove +SIGNS and www. if you expect an answer, sorry for
inconvenience, but I get tons of spam.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
iD8DBQFAPQg/ AkPEju3Se5QRAoR1AJ44rAbZYXejZjGKOyvMicc2
+6k0UwCdErAN
RBztIxh8lD/LD3S4lXbPsdQ=
=JLCt
-----END PGP SIGNATURE-----
| |
| Chris F.A. Johnson 2004-02-25, 5:34 pm |
| On Wed, 25 Feb 2004 at 20:40 GMT, Michael Heiming wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> L <L_X2828@yahoo.com> wrote:
>
> [..]
>
> for i in `seq 100 109`;do ./my_util -p $i;done
>
> Hint:
> man seq
Unfortunately, seq is not available on many systems.
The portable way to do it is:
first=100
last=109
num=$first
while [ $num -le $last ]
do
: do whatever
num=$(( $num + 1 )) ## if not a POSIX shell, use num=`expr $num + 1`
done
If there's never any need for any other numbers, one can do:
for num in 100 101 102 103 104 105 106 107 108 109
do
: whatever
done
--
Chris F.A. Johnson http://cfaj.freeshell.org/shell
========================================
===========================
My code (if any) in this post is copyright 2004, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License
| |
|
| Thanks for the info.
T.
"Chris F.A. Johnson" <c.fa.johnson@rogers.com> wrote in message
news:c1j5b7$1j6n4v$3@ID-210011.news.uni-berlin.de...
> On Wed, 25 Feb 2004 at 20:40 GMT, Michael Heiming wrote:
each[color=darkred]
>
> Unfortunately, seq is not available on many systems.
>
> The portable way to do it is:
>
> first=100
> last=109
> num=$first
> while [ $num -le $last ]
> do
> : do whatever
> num=$(( $num + 1 )) ## if not a POSIX shell, use num=`expr $num + 1`
> done
>
> If there's never any need for any other numbers, one can do:
>
> for num in 100 101 102 103 104 105 106 107 108 109
> do
> : whatever
> done
>
>
> --
> Chris F.A. Johnson http://cfaj.freeshell.org/shell
> ========================================
===========================
> My code (if any) in this post is copyright 2004, Chris F.A. Johnson
> and may be copied under the terms of the GNU General Public License
| |
| Michael Heiming 2004-02-25, 5:34 pm |
| -----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Chris F.A. Johnson <c.fa.johnson@rogers.com> wrote:
> On Wed, 25 Feb 2004 at 20:40 GMT, Michael Heiming wrote:
[color=darkred]
> Unfortunately, seq is not available on many systems.
Strange, thought I would have used it on various *nix in the past.
Your millage may vary.
- --
Michael Heiming (GPG-Key ID: 0xEDD27B94)
Remove +SIGNS and www. if you expect an answer, sorry for
inconvenience, but I get tons of spam.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
iD8DBQFAPRvkAkPEju3Se5QRAuo5AJ91miN8e26j
eJekPoCZv4wEKONRgACfSwWD
Iqb9cWB4c7IoX3RNEFZrjgg=
=NGl0
-----END PGP SIGNATURE-----
| |
| Alex Sisson 2004-02-26, 8:34 am |
| "L" <L_X2828@yahoo.com> wrote in message news:<c1il6t$1jm7kk$1@ID-92003.news.uni-berlin.de>...
> Hi,
>
> This is a newbi question on Unix/Linux script. Your help would be
> appreciated.
>
> I need to run a utility (#./my_util -p some_value) for 10 times, and each
> time a different value increased by 1 needs to be passed to the utility.
>
> The simple script to run my_util 10 times with the same parameter (-p 100)
> may look like this:
>
> for 1 2 3 4 5 6 7 8 9 10
> do
> ./my_util -p 100
> done
>
> The question is how I can use a different value (from 100 to 109) for each
> instance of my_util in the script?
>
> Thanks,
>
>
> T.
no one seems to have mentioned doing it like this (in bash at least!)
for((i=100;i<=109;i++))
do
.....
done
which is more c like so i sort of prefer it.
| |
|
| Thanks!
I'm a C programmer too, the syntaxt of the scripts looks bit different.
Take "while [ $i -lt 123 ]" as an example, all spaces seem MUST, which is
not true in C. I need some time to get familiar with that.
Thanks,
T.
"Alex Sisson" <spam@alexs.org> wrote in message
news:e4f38754.0402260453.7e309ef3@posting.google.com...
> "L" <L_X2828@yahoo.com> wrote in message
news:<c1il6t$1jm7kk$1@ID-92003.news.uni-berlin.de>...
each[color=darkred]
100)[color=darkred]
each[color=darkred]
>
> no one seems to have mentioned doing it like this (in bash at least!)
>
> for((i=100;i<=109;i++))
> do
> .....
> done
>
> which is more c like so i sort of prefer it.
| |
| Måns Rullgård 2004-02-26, 11:34 am |
| "L" <L_X2828@yahoo.com> writes:
> Thanks!
>
> I'm a C programmer too, the syntaxt of the scripts looks bit different.
> Take "while [ $i -lt 123 ]" as an example, all spaces seem MUST, which is
> not true in C. I need some time to get familiar with that.
That's right. The reason is that "[" is a program that takes
arguments the usual way.
--
Måns Rullgård
mru@kth.se
|
|
|
|
|