Tuesday, April 23, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 539  / 2 Years ago, sun, july 31, 2022, 1:35:52

In some cases, i need to use ./executable instead of simply executable when running a file in bash. What exactly is the difference and how do i know which one i should be using?



For example, i have an executable adb in DEV/ADT/sdk/platform-tools folder.



In bash, if i enter adb and run it, i get the error : The program 'adb' is currently not installed. You can install it by typing: apt-get install android-tools-adb



But if i type ./adb, it works perfectly.


More From » 14.04

 Answers
2

The first key point is that ./ specifies the current or working directory, that is, the directory that you are in now which is also the one that you see if you type the command pwd (print working directory). Bearing that in mind, bash works two ways:




  • If you specify a bare executable, such adb where no directory is given, then bash searches along the directories listed in the system PATH for an executable of that name and executes the first such executable that it finds.



    To see what directories are in the system PATH, run



    echo $PATH

  • If you specify an executable with a directory, such as ./ in your case, then bash looks only for an executable in that directory. If it is not there, it stops with an error.




In your case, you were in the DEV/ADT/sdk/platform-tools folder where the executable, adb, was located. So, when you type ./adb, bash looks for adb in the current directory and, if it finds it, it executes it.



Alternatively, when you type adb, bash looks through the directories in the PATH. Since DEV/ADT/sdk/platform-tools is apparently not in the PATH, it doesn't find the executable and complains.



Often, people avoid this problem by putting the current directory in their PATH via something like:



PATH="$PATH:."


After this is done, when you type the bare executable's name, such as adb, bash will look for it, as before, along the PATH. But since the PATH now includes the current directory, it will look there also.



The addition of . to the PATH is commonly done for personal users. Because it is more dangerous when root accidentally runs the wrong executable, this is usually not done for root.


[#24157] Sunday, July 31, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ttarum

Total Points: 417
Total Questions: 101
Total Answers: 115

Location: Maldives
Member since Wed, Nov 4, 2020
4 Years ago
;