This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Cmd line arg help in stp


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]