1

I want to know how to use switches at the command line in expect just like getopts in bash scripts.

Thanks in advance

Ramana Reddy
  • 369
  • 1
  • 8
  • 28

1 Answers1

2

See How to pass argument in expect through command line in shell script and http://www.tcl.tk/man/expect5.31/expect.1.html (Usage section).

Update: Expect is based on Tcl, and the usual method in Tcl to parse optional arguments from the command line as in getopts is the cmdline library package. This is part of tcllib, so you might need to install that if it's not already on your system.

Community
  • 1
  • 1
Colin Macleod
  • 4,222
  • 18
  • 21
  • Well this is similar to normal args but not switches. I need something like you give switches with/without args to `ls`(like `ls -l` `grep -c5 xx`) or any other `shell` commands. One way is to do using passing them at the command line and use regular expressions. Instead is there method just like `getopts` in `bash`? – Ramana Reddy Dec 03 '15 at 10:32
  • That's what the `cmdline` package does. Docs: http://core.tcl.tk/tcllib/doc/trunk/embedded/www/tcllib/files/modules/cmdline/cmdline.html – glenn jackman Dec 03 '15 at 15:47