Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to count command line arguments in expect script?

Tags:

expect

This is my simple expect script:

#!/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, which are passed by 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!

like image 853
Mr. Black Avatar asked Oct 12 '22 12:10

Mr. Black


1 Answers

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

puts "Total: [llength $argv] argument(s)"
like image 146
Frédéric Hamidi Avatar answered Oct 18 '22 03:10

Frédéric Hamidi