written a srcipt with 2 arguments

hello all
pls can anybody point me a direction of capturing 2 arguments: one a line of text the other is a file.

In paticular how can i get the file

so for exampls, i create a script called monalisa

monalisa this is an angel from the 7th heaven booboo

where monalisa is the script name, booboo is the name of the file and the rest are the line of text.]

can any body help.

Hi.
There are probably other (better) ways, but:

#!/bin/ksh

set -A ARGS $@

FILE=${ARGS[$(expr $# - 1)]}

echo $FILE

Regards.

hello
have u tried d code, its not working. i just want to get the file and rest of the argument, so that the rest of the arguments can be placed in the file

thank u

Yes, I've tryed it and works. Tough, in the example, the script only takes the file name and echoes it. From that, doing the rest is easy.... For instance:

#!/bin/ksh

set -A ARGS $@

FILE=${ARGS[$(expr $# - 1)]}

echo $@ | sed s/$FILE// >> $FILE

well i cant use sed at the moment am not on that chapter yet.

any other way would be nice. And pls can give an explanation of the code in details

Thanks

And pls the the remaining arguments goes into the middle of the file and not the begining or end of it.

Thank u.

set -A ARGS $@ defines ARGS as an array and initializes it with the script arguments.

$@ is the list of arguments itself.

FILE=${ARGS[$(expr $# - 1)]} assigns the last argument to the FILE variable. This is the way arrays are managed on ksh

$# is the number of arguments, so

expr $# -1 is the position of the last one within the array

Is this homework or something? Have a look to rule #6 on:

My intention was to give you some hints so try first to do it for yourself, then ask the forum.

Regards.