santiagoIT
santiagoIT

Reputation: 9421

bash. Usage of: './'

I did try to find the answer online but unfortunately came up empty handed. Searching for './' in combination with other keywords brings up many hits, but none that helped...

Anyhow, as you can probably tell, I am rather new to MacOs. I am running mongo from the shell. I cd into the /bin folder and start the mongo daemon with:

'./mongod'

.

If I just enter 'mongod', I get the following error:

'-bash: mongod: command not found'

What does the

'./'

in './mongod' stand for? Why is it needed? Why can't I just execute mongo by typing mongod. After all, I am in the correct directory.

Upvotes: 3

Views: 131

Answers (2)

juan.facorro
juan.facorro

Reputation: 9920

As explained in the answer by cnicutar the shell tries to match the command you enter with executables in the directories that are listed in the PATH environment variable.

Although you could add the current directory to the PATH, it's probably not a good idea to do it. This article gives some good reasons why Linux doesn't add it by default:

Its a measure to plug possible security holes. You can't run commands in the current directory without specifically calling them.

ie ./myscript.sh

To stop nasties writing a vicious shell script, placing the script in an innocent location such as /tmp and getting root to run the script. Would root run a nefarious script? If the script was named 'ls' and root did a listing, the script would automatically run.

Upvotes: 2

cnicutar
cnicutar

Reputation: 182609

After all, I am in the correct directory

But that directory isn't in the PATH. The gist of the matter is that when the shell wants to execute something it looks into a list of directories (specified in a variable called PATH). And the current directory isn't in that list.

Upvotes: 6

Related Questions