Darn dot slash ./

Why can I run an app in a shell by typing ./appname but not form the directory above it called apps by calling /apps/appname or ./apps/appname or /apps/.appname

Whats going on?
Who is Participating?
Cyclops3590Connect With a Mentor Commented:
because you have to reference the actual file.  Here's how linux app calling works
if the app is in a directory that is part of your PATH env var then you can just type
at the command line and it'll work, however if the app isn't in one of those the directories then you have to either reference the relative path name of the app or the absolute path name
for example, you want to run /root/apps/appname
you are in /home/user
you can run appname by typing
if you are in /root/apps you can type
if you are in /root/apps/someotherdir
then you can type

the .. means go one directory back and the single . means reference the current directory
means the current directory
means one directory back and
means the absolute root parent directory

cglenn3932Author Commented:
OK, so how do I add things to my path?
I use bash as my shell and that path is stored in the
file.  also at the command line you can do
PATH=$PATH:<path to be added>

mind you the path should always be absolute to avoid any weird reactions and you should NEVER add "." the single dot to your path var.  This means look at your current directory.  this is a potential security risk because if you get hacked, then someone could put a bin file on your box and just wait until you run that file and then get you then.

basically, just be real careful what you put in your path
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.


Hmm... you should be able to, unless there is permission problem.

What do you see when you "ls -l | grep apps" and "ls -l apps"? Run this command when you are one level above appname.

If you can see "x" is granted for the user/group who execute the command, then we need to check further. Else, use chmod to grant the "x" permission as appropriate.

cglenn3932Author Commented:
So, I am running this from a php script.  So, if I type what you suggest at the bash, it's permanent then?

If you run from php script, give the full absolute path, eg "/path/to/apps/appname", because "./" to the php script might be somewhere else.

yes definitely the absolute path. Trust me, if you use relative paths in a php script it can get very messy very fast and hard to trouble shoot what is happening.
>  So, I am running this from a php script.  So, if I type what you suggest at the bash, it's permanent then?
no it's not permanent, and your shell has nothing to do with your php script, usually
Use full path in php as already suggested.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.