Hi all,
I have a little problem with a expect in a bash Script.
The hull of my script:
#!/bin/sh
( expect -c '
set a \"eee\"; # the variable a
' )
echo $a; # using the variable out of the expect script
I would like to use the variable out of the expect script(in bash), but it doesn't work.
I already tried "export" and "global" but nothing works.
Could someone help me please?
Environment variables set in a child cannot affect the environment of the parent.
In this case you're setting a in a grandchild. The parentheses run the expect command in a subshell and expect itself creates a separate execution environment.
If you need to transfer data from child to parent, you need to send the data to the parent through an external channel. For instance, the exit status of the child (a value between 0 and 255) will appear as $? in the parent; the child can write a string that can be captured with something like:
var="$( do whatever; printf 'return string' )"
but note that a trailing <newline>, if present, and all trailing IFS whitespace characters will be stripped from the output by the command substitution; or the child can write data to a file and the parent can read that file at its leisure.
okay,
but with this I get the whole output of the script.
Is there no possibility to get a certiain variable?
Write the part you want the parent to see into a file in the child. Then ead from that file in the parent after the child exits.