[HPADM] SUMMARY: Processing variable number of arguments in ksh scripts:

From: Abramson, Stuart (SAbramson@Wabtec.com)
Date: Fri Oct 24 2003 - 11:33:40 EDT


hpux-admins:

Question below.

Thanks to :
        Mike Blanchette
        Brent Cramer
        Harry Pfeffer
        Sabrina Lautier
        Mitry Matyushkov

Sabrina suggested the simplest solution, below.

        #!/usr/bin/ksh
        for arg in $*; do
          print $arg
        done

Other suggest the use of "shift":

        #!/usr/bin/ksh

        echo "Number of parameters is " $#

        while [ $# -gt 0 ]; do
        echo $1
        shift
        done

Stuart Abramson | Off: 412/825-1434 | Cell: 412/417-1567 | email:
sabramson@wabtec.com

-----Original Message-----
From: Sabrina Lautier [mailto:slautier@amadeus.net]
Sent: Friday, October 24, 2003 11:19 AM
To: Abramson, Stuart
Subject: Re: [HPADM] Processing variable number of arguments in ksh
scripts:

This should do the work:

#!/usr/bin/ksh
for arg in $*; do
  print $arg
done

Rgds

Sabrina Lautier
Amadeus SAS
DEV-IIS-OAU-SYS
+33 (0)4 97 23 09 56
slautier@amadeus.net

From: "Abramson, Stuart" <SAbramson@Wabtec.com>@DutchWorks.nl on
       24/10/2003 11:09 AST

Sent by: hpux-admin-owner@DutchWorks.nl

                                                                          
 To: "Hpux-Admin (E-mail)"
        <hpux-admin@dutchworks.nl>
                                                                          
                                                                          
 cc:
                                                                          
                                                                          
                                                                          
                                                                          
                                                                          
                                                                          
 Subjec [HPADM] Processing variable number
 t: of arguments in ksh scripts:
                                                                          
                                                                          
                                                                          

hpux-admins:

I want to process a variable number of arguments to a ksh script one at a
time:

             ksh script.ksh arg1 agr2 ... argN

where:

             ##
             # script.ksh
             #

             for each argument
             do
                         symdev -sid -XXX -sa 03b write_disable $ARGX
-noprompt
             done

where $ARGX is each argument 1 to N one at a time.

How does one do that?

I don't know how many there will be at each call. There must be one
minimum.

I think you do this with "shift", somehow....

             Stuart

Stuart Abramson | Off: 412/825-1434 | Cell: 412/417-1567 | email:
sabramson@wabtec.com

***** CONFIDENTIALITY NOTE *****
The content contained in this e-mail transmission is legally privileged and
confidential information intended only for the use of the individual or
entity named herein. If the reader of this transmission is not the intended
recipient, you are hereby notified that any dissemination, distribution, or
copying of this transmission is strictly prohibited.

--
             ---> Please post QUESTIONS and SUMMARIES only!! <---
        To subscribe/unsubscribe to this list, contact
majordomo@dutchworks.nl
       Name: hpux-admin@dutchworks.nl     Owner:
owner-hpux-admin@dutchworks.nl
 Archives:  ftp.dutchworks.nl:/pub/digests/hpux-admin       (FTP, browse
only)
            http://www.dutchworks.nl/htbin/hpsysadmin   (Web, browse &
search)
***** CONFIDENTIALITY NOTE *****
The content contained in this e-mail transmission is legally privileged and confidential information intended only for the use of the individual or entity named herein. If the reader of this transmission is not the intended recipient, you are hereby notified that any dissemination, distribution, or copying of this transmission is strictly prohibited.
--
             ---> Please post QUESTIONS and SUMMARIES only!! <---
        To subscribe/unsubscribe to this list, contact majordomo@dutchworks.nl
       Name: hpux-admin@dutchworks.nl     Owner: owner-hpux-admin@dutchworks.nl
 
 Archives:  ftp.dutchworks.nl:/pub/digests/hpux-admin       (FTP, browse only)
            http://www.dutchworks.nl/htbin/hpsysadmin   (Web, browse & search)


This archive was generated by hypermail 2.1.7 : Sat Apr 12 2008 - 11:02:35 EDT