Results 1 to 7 of 7
Hi
I am writing an expect script and I wish to use environment variables that are defined outside of the script.
How can I do that?
Thanks
Ron...
- 02-08-2011 #1Just Joined!
- Join Date
- Feb 2011
- Posts
- 8
How can I use bind variables in an expect script
Hi
I am writing an expect script and I wish to use environment variables that are defined outside of the script.
How can I do that?
Thanks
Ron
- 02-08-2011 #2
Try to use export $variable
Take a look at this doc at section 3.2.3Last edited by oz; 02-08-2011 at 03:58 PM. Reason: SPAM removal
- 02-08-2011 #3Just Joined!
- Join Date
- Feb 2011
- Posts
- 8
Hi
thank you for your reply.
Are you talking about using export outside the exp script? because I tried it and it doesn't work.
This is what I am trying to do:
I have the following files:
test.sh:
echo user
read test
echo connected:$test
test.exp:
spawn ./test.sh
expect "user\r"
send "$TEST\r"
expect "connected"
TEST is an environment variable, defined in my shell and I wish to use it in my test.exp script file.
I receive the following error
"can't read "TEST": no such variable"
Thanks
Ron
- 02-08-2011 #4
Well, if I understood well, try this:
The exp.sh has the following lines (just to test):
On shell:#!/bin/bash
echo $TESTEVAR
# export TESTEVAR="112233"
# ./exp.sh
112233
- 02-08-2011 #5Just Joined!
- Join Date
- Feb 2011
- Posts
- 8
Hi
I not trying to use environment variables within a shell script, but from an expect script.
- 02-08-2011 #6
In your shell script it is $test but in the
expect script it is $TEST Is this a typo?
- 02-08-2011 #7Just Joined!
- Join Date
- Feb 2011
- Posts
- 8
These are 2 different variables.
By mistake I gave them similar names but it's not important.
The TEST variable is predefined by me.
The expect script is the one that I wish to use in order to run a shell script.
expect is used to run programs and automatically enter data for them.
In my example test.exp is the expect file that is meant to run a program called test.sh.
In test.exp I wish to use envrionment variables that I define in my shell script


Reply With Quote