It is currently Tue, 30 Nov 2021 18:12:17 GMT



 
Author Message
 Problems with Arguments in Bourne Shell Scripts

Hello out there,

I just ran into this problem.

Suppose the following two script files, 'script1' and 'script2' :

   script1 :        #!/bin/sh

                    echo Number of arguments to script 1 = $#
                    script2 "$@"

   script2 :        #!/bin/sh

                    echo Number of arguments to script 2 = $#
                    echo $1
                    echo $2
                    echo $3

When I run it WITHOUT arguments, some machines give a wrong (???) result :

      $ script1
      Number of arguments to script 1 = 0
      Number of arguments to script 2 = 1         <---- Not OK ???

      $ script1 "This is a test"
      Number of arguments to script 1 = 1
      Number of arguments to script 2 = 1
      This is a test

The previous results I get on Decstation, HP/Apollo (Domain/OS) and HP (HP-UX).
On SUN/Sparc (SunOS) I get the following correct (???) result :

      $ script1
      Number of arguments to script 1 = 0
      Number of arguments to script 2 = 0          <----- OK ???

Notice that I need the double quotes around "$@" since the arguments may
contain spaces.

No need to tell you that this is annoying if a program receives an argument
when there is actually none.

What do you think of it ?

--
-------------------------------------------------------------------------------
                                                  Antoon Demaree
     ##                                           CAD Software Support Engineer

    ##  ## ### ###    ####   #####                IMEC vzw
    ##  ##  ##  ##  ##  ##  ##                    Division VSDM
   ##  ##  ##  ##  #####   ##                     Kapeldreef 75
  ##  ##  ##  ##  ##      ##                      B-3001 Leuven
  ##  ##  ##  ##  #####   #####    VZW            BELGIUM

Interuniversity Micro-Electronics Center          e-mail:  dema...@imec.be
                                                  tel:  +32 16 281478
                                                  fax:  +32 16 281515
-------------------------------------------------------------------------------



 Mon, 19 Aug 1996 17:29:02 GMT   
 
   [ 1 post ] 

Similar Threads

1. Getting the 10th argument in Bourne shell

2. A Solaris 8 (Bourne Shell) Scripting question, regarding a log rotation script

3. help in learning how to do Bourne shell scripts then converting them to csh scripts


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software