How to count command line arguments while waiting for a script?

This is my simple script example:

#!/usr/local/bin/expect puts "Argu 1 : [lindex $argv 0]" Run --- expect example.expt Testing Output ------ Argu 1: Tesing 

I need to count the arguments that are passed on the command line. Like this:

 expect example.expt 1 2 3 4 I need the script for the following output Total: 4 arguments Arg1: 1 Arg2: 2 Arg3: 3 Arg4: 4 

How can i do this? Thanks!

+4
source share
2 answers

expect uses Tcl as its scripting language. You are looking for the llength command:

 puts "Total: [llength $argv] argument(s)" 
+4
source

Late, but I will be helpful.

This displays the number of command line arguments and a list of arguments.

 #!/usr/bin/expect -f puts "No of Command Line Arguments : [llength $argv]" puts "Arguments List " set argsCount [llength $argv]; set i 0 while {$i < $argsCount } { puts [lindex $argv $i] set i [expr $i+1]; } 

More details about waiting scenarios can be found here.

0
source

Source: https://habr.com/ru/post/1344263/


All Articles