LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Executing commands in local directory without directory path (https://www.linuxquestions.org/questions/linux-newbie-8/executing-commands-in-local-directory-without-directory-path-4175561775/)

NotionCommotion 12-18-2015 10:33 AM

Executing commands in local directory without directory path
 
I am a little confused. Why must I include the directory path when executing bacwi?

Code:

pi@raspberrypi ~/bacnet-stack-0-8-0/bin $ pwd
/home/pi/bacnet-stack-0-8-0/bin
pi@raspberrypi ~/bacnet-stack-0-8-0/bin $ ls -l bacwi
-rwxr-xr-x 1 pi pi 106865 Dec 12 16:05 bacwi
pi@raspberrypi ~/bacnet-stack-0-8-0/bin $ bacwi -1
-bash: bacwi: command not found
pi@raspberrypi ~/bacnet-stack-0-8-0/bin $ ./bacwi -1
Received I-Am Request from 1234, MAC = 192.168.1.201.186.192
Received I-Am Request from 1234, MAC = 192.168.1.201.186.192
;Device  MAC (hex)            SNET  SADR (hex)          APDU
;-------- -------------------- ----- -------------------- ----
  1234    C0:A8:01:C9:BA:C0    0    00                  1476
;
; Total Devices: 1
pi@raspberrypi ~/bacnet-stack-0-8-0/bin $


jdkaye 12-18-2015 10:42 AM

What is the output of this command?
Code:

echo $PATH
On my system my home directory is not included in the PATH variable.
jdk

Keith Hedger 12-18-2015 10:42 AM

The current working directory is not normally part of the search path for comands, try
Code:

echo $PATH
To see what directorys get searched, if you want to run a command in the current directory without changing the PATH variable use "./" which is a releative path to the current directory so use
Code:

./bacwi

jdkaye 12-18-2015 10:45 AM

@Keith Hedger
Great minds think alike. ;)
jdk

Keith Hedger 12-18-2015 10:47 AM

Quote:

Originally Posted by jdkaye (Post 5465947)
@Keith Hedger
Great minds think alike. ;)
jdk

Aint it spooky when that happens.

NotionCommotion 12-18-2015 10:51 AM

Code:

pi@raspberrypi ~/bacnet-stack-0-8-0/bin $ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games
pi@raspberrypi ~/bacnet-stack-0-8-0/bin $

Thanks. I incorrectly thought that the current directory was always part of the search path for commands.

Keith Hedger 12-18-2015 10:53 AM

Don't forget to mark the thread SOLVED

jdkaye 12-18-2015 10:58 AM

1 Attachment(s)
Glad to have been of service. As a service to others please mark this thread as [SOLVED]. You can use the Thread Tools menu located above your first post in this thread (see the attachment).
jdk

jdkaye 12-18-2015 11:00 AM

:)Great minds still think alike. What did you have for breakfast?
jdk

Keith Hedger 12-18-2015 11:04 AM

Quote:

Originally Posted by jdkaye (Post 5465957)
:)Great minds still think alike. What did you have for breakfast?
jdk

Don't eat breakfast it's for wimps!

normanlinux 12-19-2015 07:21 AM

No current directory in $PATH
 
There is a very good reason why there is no current directory (.) in your $PATH

It is a potential security risk - although it would, of course, be comforting for people coming from windows to see that they could f**k up their system in a way that they were used to.

Back in the eighties it was common (normal?) to prepend $PATH with current directory. However this creates a security hole in that an executable file, in your home directory, with the same name as a system program could do all manner of nasty things. So we moved to putting the current directory at the end of the $PATH.

Then it was realised that there could still be problems, so for the past 20 - 25 years the advice has always been not to include current (or home) directory in $PATH - but to use ./ to reinforce that you consciously wish to use a local file.

Nothing wrong with having a bin directory within your home directory - in fact it's a good idea - but put it at the end of your $PATH


All times are GMT -5. The time now is 05:55 PM.