I have a bash script which can login to Cisco switch and shut/noshut any port I have defined in it.

What I want is that I can add variable, like I can define port number in a command like this:

./cisco.sh 10 #10 is the port number

But the script is not letting me add any variable and gives the following error:

can't read "1": no such variable
    while executing "set PORT "$1""

Here is the code of the script I am using:

#!/usr/bin/expect -f
set timeout 20
set IPaddress ""
set Username "zaib"
set Password "zaib"
set PORT "$1"
spawn ssh -o "StrictHostKeyChecking no" $Username@$IPaddress
expect "*assword: "
send "$Password\r"
expect ">"
send "enable\r"
expect "*assword: "
send "$Password\r"
send "conf term\r"
send "interface gigabitEthernet 1/0/$PORT\r"
expect "#"
send "shut\r"
expect "#"
send "exit\r"
expect "#"
send "exit\r"
send "wr\r"
send "exit\r"

1 Answer 1


Maybe I was too much in a hurry. I had to add

set port [lindex $argv 0]

to get $1 variable added in the script.

Thanks :)


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .