0

Basic question I know but this is early days for me in Linux and I really want to make sure I understand this before moving on (adding git to my shared host).

From what I understand you are giving the directions to bash on where to find a folder so if you need to write to it (like install a program) you can? Bash being the environment used to work in (eg cygwin \ gitbash?).

Explain it like Im five. Thanks.

3

From wiki:

Multics originated the idea of a search path. The early Unix shell only looked for program names in /bin, but by Version 3 Unix the directory was too large and /usr/bin, and a search path, became part of the operating system.[1]

PATH is a :-separated list of directories that shells (exec*p functions) go through to find an executable file.

With PATH=/a:/b:/c, when you run x, the shell will test for an executable /a/x, then /b/x (if the previous test failed) and finally /c/x (if the previous test failed), failing if x wasn't found in any of the PATH directories.

  • Ok so when I add the variable to .bashrc and output the PATH I'm seeing the filepath of every program that the shell knows, and I'm adding the location of the new program. If it traverses every possible path to find an executable, doesn't a really long PATH affect speed, or is speed irrelevant in this case. Is bash just one type of shell of the interface for the shell? – JPB Jul 13 '17 at 12:04
  • If you split the PATH on : and list executable files in each component, you will get a list of all executable callable from a shell without a path (no-slashes). Yes, long PATHs do affect speed, of course, but shells typically cache the lookup results (the cache is accessible with a shell builtin named hash) to counter this. Bash is one type of shell. A shell is more or less an interface to the system/kernel. – PSkocik Jul 13 '17 at 12:08
0

PATH does the same thing it does on Windows. Directory/ies for your executables commands and it's there so you don't have to type the full path every time.

That's why you can use cp instead of /usr/bin/cp. You can lookup all those paths with which command, you'll get the full path afterwards which you would need to type if the basedirectory wasn't in your $PATH variable.

  • Only time I've used PATH on windows was to add my global node modules folder which was the start of this long journey. Thanks for your input, have no idea what cp is though? ELI5? Use cp for what? Edit: Ah ok I get it now. Thanks. – JPB Jul 13 '17 at 12:08
  • It's the copy command. – Ziazis Jul 13 '17 at 12:10
  • Cool, I know that must be simple to you but even the idea that the copy command itself resides in a folder somewhere, that is accessed by a shortcut (the path variable) is helpful in putting things in perspective. – JPB Jul 13 '17 at 12:23
  • which is poorly standardized and should be eschewed in favor of the POSIX-mandated replacement type. – tripleee Jul 13 '17 at 15:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.