One of expect parameter processing
Expect is a very powerful script, although the online resources are very classic, but very few, I put my own test script to paste, only for reference
- #! / usr/bin/expect- F
- Proc Help {} {
- Puts {usage: <ivie_ip> [-P <password>] [cmd] }
- }
- If {$argc<1} {help ; Exit}
- Set IP [ lindex $argv 0 ]
- Set Password Rootroot
- Set cmd ""
- For {set I 1} {$i<$argc} {incr i 1} {
- set M [lindex $argv $i]
- Switch $m {
- "-P" { if {$argc<3} {help ; exit 1 }
- Set Password [lindex $argv [expr 1+$i ]]
- INCR I 1
- } default { puts "MM: $m"
- lappend cmd $m
- }
- }
- }
- Puts "$ip-P $password $cmd"
I also like to use loops and case processing when I deal with Bash, which is simple and operable.
There are options behind switch:-exact mode,-glob mode,-regexp mode, default representation-glob mode. The-exact method is the exact match, and the matching method of the-glob mode is the same as the string Match command, and the-regexp way is the matching way of the regular expression.
One of expect parameter processing