Executing an Expect script from various places

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

  • My Linux home directory ( #!/usr/bin/expect )
  • Transparent 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 link of the Expect executable to the first line of the file.

How can I get the correct Expect executable for the corresponding directory?

+4
source share
1 answer

If your path is correctly installed on both servers, you can use /usr/bin/env :

 #!/usr/bin/env expect 

This will use the expected result found in PATH ( /usr/bin in one case, /clearlib/vobs/otherdir/bin in another)

Instead of using env , as in the example, the interpreter is searched and found at the time the script is run.
This makes the transfer script more portable, but also increases the risk that the wrong interpreter is selected because it searches for a match in every directory in the path of the executable search.
It also suffers from the same problem that the env binary path can also be different for each machine.

And if you have a problem setting the correct PATH , then /usr/bin/env questions regarding the features of the shebang line may help.

+3
source

Source: https://habr.com/ru/post/1446032/


All Articles