LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-16-2015, 10:01 AM   #1
Selecta
LQ Newbie
 
Registered: Sep 2015
Distribution: Ubuntu 14.04
Posts: 19

Rep: Reputation: Disabled
Pathing: Directory vs Executable and Relative vs Absolute


I'm very new to Linux, less than a week, but I've got my server (Ubuntu 14.04 desktop) up and running and done some major work getting two custom applications running. Coming from the dark side (Windows) I'm having trouble with the way some things are handled in Linux with regard to pathing.

Assume I have a .conf file with a line like this:

Quote:
GAMEPATH = "/clown/hat"
It doesn't seem that I can tell if "hat" is a directory or an executable. It also doesn't seem like I can tell if that's an absolute path from root or if it's relative to the current directory.

No doubt I'm missing something with my newbness so I could really use a bit of help here. Right now it's taking me forever configuring these two apps I'm working on that have tons of path statements via trial and error so any thoughts would be most welcome.

Thank you!
 
Old 09-16-2015, 10:11 AM   #2
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Distribution: UBUNTU 5.10 since Jul-18,2006 on Intel 820 DC
Posts: 804

Rep: Reputation: 186Reputation: 186
(1) Since it starts with a forward slash, it is an absolute path (starting from the root).
(2) AFAIK, paths are given only for directories. Effectively, it tells the shell to look in the specified path (or list of paths) (either absolute or relative) to locate the called executable.

Note that unlike DOS, the current directory ISN'T automatically in the path. This means that even if you in the directory where the executable is, you cannot just call the program by giving just it's name as PROGNAME or whatever. You have to give ./PROGNAME (unless ./ is in the PATH). It is preferred by some developers.

OK
 
1 members found this post helpful.
Old 09-16-2015, 11:04 AM   #3
Selecta
LQ Newbie
 
Registered: Sep 2015
Distribution: Ubuntu 14.04
Posts: 19

Original Poster
Rep: Reputation: Disabled
AnanthaP - Now that I think about the issue must be more with the application developers. What you say makes sense but, in this current effort, I've seen .conf files that take a path that starts with / and then tack it on to the end of a prefix path. The ./executable thing I knew but I didn't really understand why it worked in that manner.

Thank you very much for your assistance.
 
Old 09-16-2015, 12:36 PM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,243

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
Standards wise you would find that AnanthaP's information is correct, but as usual there is always more ways to do things.

I would suggest that where you have seen a variable assigned as you have demonstrated only to be later attached to another path would be so it ensures that the existing path that is being
appended to will have the necessary path delimiter (/) included.

An example is probably easiest:
Code:
GAMEPATH="/clown/hat"

from_root="/usr/local"

full_path_from_root="$from_root$GAMEPATH"
Consider what the implication would be if you were to remove the leading slash from the GAMEPATH variable.
 
1 members found this post helpful.
Old 09-16-2015, 04:06 PM   #5
Selecta
LQ Newbie
 
Registered: Sep 2015
Distribution: Ubuntu 14.04
Posts: 19

Original Poster
Rep: Reputation: Disabled
grail - In your example would it be more appropriate to do this?

Quote:
GAMEPATHSUFFIX ="clown/hat"

from_root="/usr/local"

full_path_from_root="$from_root(insertfrontslashsomehow)$GAMEPATH"

Then at least you'd know it was a relative path. Of course I'm completely unsure... just trying to learn.

Could you also maybe do this?

Quote:
from_root="/usr/local/"
 
Old 09-16-2015, 11:14 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Just try it
NB: when doing this, you are just assigning strings - the meaning isn't evaluated until you try to use it.
 
Old 09-17-2015, 02:43 AM   #7
zhjim
Senior Member
 
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,748
Blog Entries: 11

Rep: Reputation: 233Reputation: 233Reputation: 233
Quote:
Originally Posted by Selecta View Post
The ./executable thing I knew but I didn't really understand why it worked in that manner.
Not sure if you use this kinda way to express a path in your config just some knowledge why it works in general.
In each directory you have at least two hidden files. One beeing "." and the other beein ".." (without quotes). "." refers to the current working directory while ".." refers to the directory the current working directory resides in. Or just the directory above.

On a commandline do a "ls -a" which shows all hidden files.

If your unsure if a path is just only directories or also includes a file use the "file" binary on command line. "file /usr/local/clown/hat".
 
Old 09-17-2015, 08:18 AM   #8
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,243

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
At the end of the day there is no hard and fast right or wrong. My suggestion would be just to make sure however you choose to do it that you do it uniformly throughout your code.
The other suggestion would be to place a comment near the first time you do it so then you (or others looking at the code) have something to refer to on what the expected format is
 
Old 09-17-2015, 08:25 AM   #9
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,599

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
Quote:
Originally Posted by Selecta View Post
AnanthaP - Now that I think about the issue must be more with the application developers. What you say makes sense but, in this current effort, I've seen .conf files that take a path that starts with / and then tack it on to the end of a prefix path. The ./executable thing I knew but I didn't really understand why it worked in that manner.

Thank you very much for your assistance.
The "why" is that it provides better security.

The reason is that if you set your working directory somewhere else - then you may be executing commands taken from that directory and not the command you expect. Think of it as a preventative of a trojan malware attack...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] tar absolute and relative path mmhs Linux - Newbie 13 08-09-2012 09:09 PM
Absolute/Relative Pathnames (.) (..) Pl3th0r4x Linux - General 10 02-21-2012 02:12 AM
relative/absolute paths? mkohler Linux - Newbie 3 11-13-2010 04:45 AM
Absolute and relative paths Gins Linux - General 6 11-08-2008 09:48 PM
relative to absolute path vishalbutte Programming 4 01-14-2006 04:17 PM


All times are GMT -5. The time now is 10:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration