Home > Blockchain >  Shell libraries location mechanism in Linux?
Shell libraries location mechanism in Linux?

Time:07-29

In Linux there are standard locations for shared binary libraries like /usr/local/lib and /usr/lib and a standard mechanism that allows linker to locate libraries placed there without full path specified.

I'm looking for a similar mechanism for shell libraries (i.e., shell scripts that are called from another shell scripts) that allows shell to locate a library even if its path isn't specified.

I know that I can find out the caller's path and calculate the path to a library from that but I don't think that's a good approach. First of all, because there's no reliable way to determine the location of a shell script.

So, does Linux provide a mechanism to locate shell libraries?

CodePudding user response:

shell scripts that are called from another shell scripts

Calling any command (that doesn't contain a / in the command name) is searched in PATH. Add your script to PATH or add a dir to PATH.

PATH is searched when sourceing a script in the same way as for the command, just the command doesn't have to have executable permissions set..

  • Related