-   Linux - Newbie (
-   -   Problem in exporting variable from bash script to expect script (

uk.engr 06-13-2012 02:19 AM

Problem in exporting variable from bash script to expect script
Assalam o Alaikum.

I can easily export variable from bash to bash script but not from bash to expect script. Here are my scripts:
[root@Zohaib 04]# vim
mkdir -p /tmp/logs_auto
cp -n Email_words.txt /tmp/
export gxip

[root@Zohaib 04]# vim
#!/usr/bin/expect -f
echo "$gxip"
spawn ssh root@$gxip
expect "*password*" {
send "123\r"

[root@Zohaib 04]# . ./

can't read "gxip": no such variable
while executing
"echo "$gxip" "
(file "" line 8)

David the H. 06-13-2012 09:57 AM

Please use ***[code][/code] tags*** around your code and data, to preserve formatting and to improve readability. Please do not use quote tags, colors, or other fancy formatting.



There can't be any spaces around the equals sign when setting a shell variable.

micropanther 06-13-2012 10:48 AM

Wow, that took a lot of digging.

Your answer is found in the TCL/TK Wiki

I hate redirection as an answer so here is what I got to work
  1. There is a space after the "=" in your gxip= 192. ... statement. No spaces allowed unless you put quotes around the string.
  2. echo is not an expect command. Use puts instead.
  3. The variable you want to use is a global environment variable in the environment of the bash shell. Tcl/Tk gets all the global environment vars into an array named env. You get to env by referencing $::env(name_of_the_global_env_var). So in your case you need to puts $::env(gxip). Similar fixes for other lines where gxip is used.

uk.engr 06-14-2012 01:57 AM

Thanks you so much. it works thanks a lot............................................

All times are GMT -5. The time now is 11:26 AM.