Operating System - HP-UX
1822521 Members
2746 Online
109642 Solutions
New Discussion юеВ

Calling a script with a list

 
SOLVED
Go to solution
Leo The Cat
Regular Advisor

Calling a script with a list

Hi

Here the call
/test/myscript.ksh user1 user2 user3 ....

The list of user is not defined

How to read all parameters in a loop ?

if the list was in a file no problem but I want this list coming thru the commad line ....

How to do the tric ?

Bests regards
Den
5 REPLIES 5
James R. Ferguson
Acclaimed Contributor
Solution

Re: Calling a script with a list

Hi Den:

#!/bin/sh
for X in $@
do
echo ${X}
shift
done

Regards!

...JRF...
Steven Schweda
Honored Contributor

Re: Calling a script with a list

> shift

This buys you what, exactly?
Dennis Handly
Acclaimed Contributor

Re: Calling a script with a list

>Steven: This buys you what, exactly?

Right, not so much, unless you are working on $1.

while [ $# -ne 0 ]; do
echo "$1"
shift
done
Leo The Cat
Regular Advisor

Re: Calling a script with a list

JRF's solution is doing the trick perfectly !
Thanks again
James R. Ferguson
Acclaimed Contributor

Re: Calling a script with a list

Hi (again) Den:

As already noted, the 'shift' I imposed is meaningless unless you wanted to reference '$1'. I was oscillating between using the 'for' and a 'while' loop along the lines Dennis wrote.

Regards!

...JRF...