How to pass argument in Expect through the command line in a shell script

lk121 :

I am passing argument in Expect through the command line in a shell script.

I tried this

#!/usr/bin/expect -f
    
set arg1 [lindex $argv 0]
    
spawn lockdis -p
expect "password:" {send "$arg1\r"}
expect "password:" {send "$arg1\r"}
expect "$ "

But it's not working. How can I fix it?

bartimar :

If you want to read from arguments, you can achieve this simply by

set username [lindex $argv 0];
set password [lindex $argv 1];

And print it

send_user "$username $password"

That script will print

$ ./test.exp user1 pass1
user1 pass1

You can use Debug mode

$ ./test.exp -d user1 pass1

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to pass argument to maven from shell script

How to pass a variable as an argument to a CasperJS script through the command line?

Pass command line argument to vagrant shell script provisioner

How to pass a command line argument to a nested script?

How do you pass an argument to a composer script from the command line?

Pass an array as command line argument to the script

Pass command line -- argument to child script in Yarn

Pass command line argument to python script

How to pass variable to exec command in expect script?

Pass a list to a Python script as a command line argument

how to pass a command line argument in the awk script

How to pass an argument to a shell script?

How to pass a command from Shell script to command line

Java command line arguments through shell script

howto pass an argument to an android app, which is started through shell command

How to pass the argument in expect shell script during runtime

How to pass shell variables as Command Line Argument to a shell script

Command line options with argument in shell script

How can I pass a command line argument into a shell script?

Expect script to run shell command

passing '*' as command line argument to shell script

Shell Script :How to pass script's command-line arguments through to commands that it invokes?

Pass argument from shell script to Python script without having to specify argument on command line

Shell script -e command line argument not recognized

How to pass variables as parameters to Bigquery command line in shell script

How to pass tablename as parameter to Bigquery command line in shell script

How to pass an argument into a file in shell script?

Pass directory to python script as command line argument

How to pass command line arguments to script instead of shell