One of expect parameter processing

Source: Internet
Author: User
Tags glob

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

  1. #! / usr/bin/expect- F

  2. Proc Help {} {
  3. Puts {usage: <ivie_ip> [-P <password>] [cmd] }
  4. }

  5. If {$argc<1} {help ; Exit}
  6. Set IP [ lindex $argv 0 ]

  7. Set Password Rootroot
  8. Set cmd ""
  9. For {set I 1} {$i<$argc} {incr i 1} {
  10. set M [lindex $argv $i]
  11. Switch $m {
  12. "-P" { if {$argc<3} {help ; exit 1 }
  13. Set Password [lindex $argv [expr 1+$i ]]
  14. INCR I 1
  15. } default { puts "MM: $m"
  16. lappend cmd $m
  17. }
  18. }
  19. }


  20. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.