I am trying to run my Expect script from two different locations and it will work with the following Expect executables referenced:
#!/usr/bin/expect
)#!/clearlib/vobs/otherdir/bin/expect
)The problem is that I cannot run the script in both places unless I change the reference of the Expect executable location to the first line of the file.
How can I get the correct instance of the Expect executable for the corresponding directory?
If your path is correctly set on both servers, you could use /usr/bin/env
:
#!/usr/bin/env expect
That would use the expect as found in the PATH
(/usr/bin
in one case, /clearlib/vobs/otherdir/bin
in the other)
By instead using
env
as in the example, the interpreter is searched for and located at the time the script is run.
This makes the script more portable, but also increases the risk that the wrong interpreter is selected because it searches for a match in every directory on the executable search path.
It also suffers from the same problem in that the path to theenv
binary may also be different on a per-machine basis.
And if you have issue with setting the right PATH
, then "/usr/bin/env
questions regarding shebang line pecularities" can help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With