Find the answer to your Linux question:
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...
  1. #1
    Just 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

  2. #2
    Just Joined! rafatmb's Avatar
    Join Date
    Feb 2011
    Location
    Brazil
    Posts
    25
    Try to use export $variable

    Take a look at this doc at section 3.2.3
    Last edited by oz; 02-08-2011 at 03:58 PM. Reason: SPAM removal

  3. #3
    Just 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

  4. #4
    Just Joined! rafatmb's Avatar
    Join Date
    Feb 2011
    Location
    Brazil
    Posts
    25
    Well, if I understood well, try this:


    The exp.sh has the following lines (just to test):
    #!/bin/bash
    echo $TESTEVAR
    On shell:
    # export TESTEVAR="112233"
    # ./exp.sh
    112233

  5. #5
    Just Joined!
    Join Date
    Feb 2011
    Posts
    8
    Hi
    I not trying to use environment variables within a shell script, but from an expect script.

  6. #6
    Linux Engineer rcgreen's Avatar
    Join Date
    May 2006
    Location
    the hills
    Posts
    1,114
    In your shell script it is $test but in the
    expect script it is $TEST Is this a typo?

  7. #7
    Just 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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...