0

I have this situation in which the same command/program (eg: myScript) is present in two locations, /usr/bin and /usr/local/bin. Both these locations are in the PATH.

When I run

$ myScript
  1. How do I know from which location myScript will be picked up?
  2. Can I force the use of one of the locations (without having to delete myScript from one of the locations)?

1 Answers1

1
  1. myScript will be picked up from the FIRST location it is mentioned in the PATH variable. You can test this using which myScript (it should return the location first seen in PATH).
  2. Use absolute or relative addressing to call the script directly. Instead of myScript, try /path/to/myScript referring to the one you wish to use in your code.
Lee
  • 26
  • Okay. Thanks. Do you think it would be a good idea to add an alias like: alias myScript '/path/to/myScript'? – Mukul Rana Sep 27 '18 at 09:11
  • It's a matter of preference, I guess. Adding an alias is another way to go about it. Best practice would be to alias the script only, and not alias command line inputs to the script. – Lee Sep 27 '18 at 09:14
  • Understood. Thank you very much for your help. – Mukul Rana Sep 27 '18 at 09:15
  • https://unix.stackexchange.com/questions/85249/ Observe that the questioner has asked a generic question. – JdeBP Sep 27 '18 at 09:46