I have read that the shell searches the command in all the directories available in the PATH variable. My first question is what if 2 directories have the files for a command, which one will be executed ? Second question is, does the shell searches in the directories shown in PATH variable recursively or not ? Thanks.
1 Answer
what if 2 directories have the files for a command, which one will be executed ?
The first one wins i.e. the first directory in the PATH
where the desired file is found, is executed.
does the shell searches in the directories shown in PATH variable recursively or not ?
Non-recursively.
-
Can we decide the order of directories in PATH variable, and if yes , how ?– ChiragJan 8, 2017 at 5:49
-
@user3150716
PATH
takes:
separated directories to look at; just maintain the order you want while declaring thePATH
.– heemaylJan 8, 2017 at 5:50 -
@user3150716 You put the first one, then a colon, then the second one, then a colon then the third one. You might also find
type command
useful, it shows which command is used.– icarusJan 8, 2017 at 5:51