Run binary with ./ in Ubuntu

I decided to learn C ++ (I program in C at work), and I read several manuals (and a lot of posts here about Stack Overflow). OK, so I typed the standard word "hello word" in C ++, compiled with GCC on my Ubuntu as a "test".

Then I tried to run it by typing "test" and pressing enter. Nothing. Turns out I have to run it with "./test". Alright, alright, I'll do it from now on. But why? "./" just says that what I have to start is in the current directory ... Is the current directory not always part of PATH when the OS is looking for something to start? Can I do it?

+3
source share
7 answers

Yes, the current directory is not part of your PATH. You do not want this to be, because then you could be in a directory in which there was a malicious program that you did not know about what you were running.

, /usr/bin/grep, , Bad Person grep, grep, grep , /usr/bin/grep.

, , ./ PATH ~/.profile ~/.bash_profile, .

, 15 , Unix- .

+10

"." PATH, - "" - .

+6

, Unix "test"...

+3

script, , type./ .

+1

Even if the current directory is at the very beginning of $ PATH, "test" will still not run it on (most?) Shells, since "test" is a shell built-in command.

+1
source

Not having '.' (current directory) in PATH is a minor security measure. You can always add it if you want, although this is not the best practice.

0
source

If this is unclear, this is the aspect in which Windows differs from Unix / Linux. On Windows, the current directory is implicitly in the path.

0
source

Source: https://habr.com/ru/post/1699134/


All Articles