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.
grial
April 29, 2008, 3:42am
2
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
grial
April 29, 2008, 4:20am
4
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.
grial
April 29, 2008, 5:06am
7
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:
SIMPLE RULES OF THE UNIX FORUMS: (1) No flames, shouting (all caps), sarcasm, bullying, profanity or arrogant posts. (2) No negative comments about others or impolite remarks. Be patient. No BSD vs. L | The UNIX and Linux Forums
My intention was to give you some hints so try first to do it for yourself, then ask the forum.
Regards.