1

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.

0

1 Answer 1

4

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.

3
  • Can we decide the order of directories in PATH variable, and if yes , how ?
    – Chirag
    Jan 8, 2017 at 5:49
  • @user3150716 PATH takes : separated directories to look at; just maintain the order you want while declaring the PATH.
    – heemayl
    Jan 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.
    – icarus
    Jan 8, 2017 at 5:51

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