SET command

Hi Unixers, :slight_smile:
In a shell script i found the following statements
mline='grep\^ 1111 emaster.dbf
set -- $mline
The first statement searches the emaster.dbf file for the code 1111 and ifit finds any such line it gets that line and stores it in mline.
But iam getting little bit confusion with second statemnt.I know that the set command is used to set the command line arguments.
Then what is the purpose of -- . :confused:

Suppose if mline=1111 Ravi M IT ORACLE
then
$1=1111 $2=Ravi $3=M $4=IT $5=ORACLE.

here how the symbol -- works?
Any help pls.

cheers
Ravi Raj Kumar

set -- [ arguments ... ]

With -- and arguments, replace the positional parameters with the supplied arguments

Did you try the man pages ? They are a very good source of information.
man sh says

              --      If no arguments follow this option, then  the  positional
                      parameters  are unset.  Otherwise, the positional parame-
                      ters are set to the args, even if some of them begin with
                      a -.

See this

[/tmp]$ cat try.sh
#! /bin/sh

arg="first second third"

if [ $# -eq 3 ] ; then
    echo $1
    echo $2
    echo $3
fi;

set -- $arg
echo $1
echo $2
echo $3
[/tmp]$ ./try.sh 12 23 34
12
23
34
first
second
third
[/tmp]$ ./try.sh
first
second
third
[/tmp]$ 

well, :slight_smile:
we can also do that simply by saying set $arg
is'nt it?

cheers
RRK

Yes you can do that as well. With -- you can unset the variables $1 et al. The difference appears when you want to unset the variables.