This is the mail archive of the
systemtap@sourceware.org
mailing list for the systemtap project.
Re: Cmd line arg help in stp
- From: William Cohen <wcohen at redhat dot com>
- To: Varun Chandramohan <varunc at linux dot vnet dot ibm dot com>
- Cc: systemtap at sources dot redhat dot com
- Date: Mon, 06 Apr 2009 13:35:16 -0400
- Subject: Re: Cmd line arg help in stp
- References: <49D9A70D.8060405@linux.vnet.ibm.com>
Varun Chandramohan wrote:
> Hi,
>
> Iam looking at a way to iterate the multiple command line
> arguments i passed with my script.
>
> #stap xyz.stp <arg 1> <arg2> <arg3>
>
> arc are strings. '$#' gives me the max number of arguments passed and
> '$1' , '$2' .... gives each of the args. But the number of args iam
> passing to the script is not fixed.
>
> Can somone help me with writing a sample code in system tap that can do
> this? I need something similar to what the below script does
>
> while [ $# -gt 0 ]
> do
>
> echo $1
> shift
>
> done
>
> or in c we have argc and argv []. Any suggestions? Iam new to stap
> scripting so please suggest a method to do this or point me to some code
> that already does something similar. Thanks.
>
> Regards,
> Varun
You might be able to use the tokenize function and pull out the arguments from a
single command line string. Something like the following:
probe begin
{
i = 1
s = tokenize(@1, " ")
while (s != "") {
printf("element %d: %s\n", i, s);
s = tokenize("", " ");
++i
}
}
Example output:
$ stap tokennize.stp "a b c d goody baddy"
element 1: a
element 2: b
element 3: c
element 4: d
element 5: goody
element 6: baddy
-Will