Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executing an Expect script from different locations

I am trying to run my Expect script from two different locations and it will work with the following Expect executables referenced:

  1. My linux home directory (#!/usr/bin/expect)
  2. A clearcase view on another server (#!/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?

like image 946
Jake88 Avatar asked Oct 06 '22 00:10

Jake88


1 Answers

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 the env 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.

like image 68
VonC Avatar answered Oct 09 '22 00:10

VonC