Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 06-13-2012, 03:19 AM   #1
Registered: Apr 2012
Posts: 131

Rep: Reputation: Disabled
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)

Last edited by uk.engr; 06-13-2012 at 03:26 AM.
Old 06-13-2012, 10:57 AM   #2
David the H.
Bash Guru
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1954Reputation: 1954Reputation: 1954Reputation: 1954Reputation: 1954Reputation: 1954Reputation: 1954Reputation: 1954Reputation: 1954Reputation: 1954Reputation: 1954
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.
Old 06-13-2012, 11:48 AM   #3
LQ Newbie
Registered: Oct 2007
Location: Charlotte, NC
Distribution: Ubuntu 10.04, Davinci (MacOS/X)
Posts: 20

Rep: Reputation: 0
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.
Old 06-14-2012, 02:57 AM   #4
Registered: Apr 2012
Posts: 131

Original Poster
Rep: Reputation: Disabled
Thanks you so much. it works thanks a lot............................................


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem running an Expect script within a Bash script mbeipi Programming 8 03-15-2011 05:07 PM
[SOLVED] /usr/bin/expect : Script to check server load using both expect and bash Soji Antony Programming 1 07-28-2010 12:27 AM
Problem with bash script - variable name within variable name steven.c.banks Linux - Newbie 3 03-10-2009 04:08 AM
Bash Script Help - Trying to create a variable inside script when run. webaccounts Linux - Newbie 1 06-09-2008 03:40 PM
Bash Script Variable Problem jimmy512 Programming 5 05-11-2007 08:38 AM

All times are GMT -5. The time now is 09:54 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration