Thread: A.out w/o ./

Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    20
    Rep Power
    0

    A.out w/o ./


    is there something i can put in my bin file that allows me to execute a.out without having to put ./ in front of it. want to be able to do this from any subdirectory by just typing a.out
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2009
    Location
    Nebraska, USA
    Posts
    867
    Rep Power
    275
    You should be able to just place the BIN file in one of the PATH directories and set its permissions correctly.
  4. #3
  5. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,616
    Rep Power
    4247
    You just need to set your PATH variable to look at your current directory as well. The way to do this depends on what shell you are using:

    csh or tcsh (FreeBSD uses this by default):
    setenv PATH=${PATH}:.

    bash, sh, ksh (OpenBSD uses ksh by default):
    export PATH=${PATH}:.

    The . at the end of the line tells the shell to look in the current directory along with the list of other directories, when it looks for a program to run. Now you can run a.out without a ./ in front.

    Put that line in your .tcshrc or .kshrc or whatever and it'll be set for you automatically when you log in.
    Last edited by Scorpions4ever; May 18th, 2013 at 05:56 PM.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  6. #4
  7. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,379
    Rep Power
    1871
    Putting . in your PATH is a security hole.

    Joe Hacker manages to get access to your machine, and creates a file called 'sl' in the /tmp directory (which is usually world-writable).

    Innocent user comes along sometime later, changes directory to /tmp, and in a fat fingered moment, manages to type 'sl' instead of 'ls'. So instead of a directory listing, they have a world of pain.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    20
    Rep Power
    0
    Originally Posted by DonR
    You should be able to just place the BIN file in one of the PATH directories and set its permissions correctly.
    what would i put in the bin file exactly?
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    20
    Rep Power
    0
    Originally Posted by Scorpions4ever
    You just need to set your PATH variable to look at your current directory as well. The way to do this depends on what shell you are using:

    csh or tcsh (FreeBSD uses this by default):
    setenv PATH=${PATH}:.

    bash, sh, ksh (OpenBSD uses ksh by default):
    export PATH=${PATH}:.

    The . at the end of the line tells the shell to look in the current directory along with the list of other directories, when it looks for a program to run. Now you can run a.out without a ./ in front.

    Put that line in your .tcshrc or .kshrc or whatever and it'll be set for you automatically when you log in.
    what would i put in the bin file?
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2009
    Location
    Nebraska, USA
    Posts
    867
    Rep Power
    275
    I was assuming that your A.OUT command was your BIN file that you wanted to execute from any directory.
    If thats not the case, then, will need more info on what you are wanting to accomplish.
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    20
    Rep Power
    0
    can anybody explain to me in real basic logic why you need to use ./ before a.out to execute? Doesn't . move you up one directory?
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    20
    Rep Power
    0
    what if you have a seperate a.out file in many directories. how will it know which one to execute? will it execute the one in the current directory?
    Originally Posted by Scorpions4ever
    You just need to set your PATH variable to look at your current directory as well. The way to do this depends on what shell you are using:

    csh or tcsh (FreeBSD uses this by default):
    setenv PATH=${PATH}:.

    bash, sh, ksh (OpenBSD uses ksh by default):
    export PATH=${PATH}:.

    The . at the end of the line tells the shell to look in the current directory along with the list of other directories, when it looks for a program to run. Now you can run a.out without a ./ in front.

    Put that line in your .tcshrc or .kshrc or whatever and it'll be set for you automatically when you log in.
  18. #10
  19. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,616
    Rep Power
    4247
    Originally Posted by web9452
    can anybody explain to me in real basic logic why you need to use ./ before a.out to execute? Doesn't . move you up one directory?
    No, ./ refers to the current directory, ../ (note the two dots) moves you up one directory.

    As to why you need to use ./ before a.out, that's because the current directory is not part of the PATH environment variable on most *nix systems (see salem's explanation for why). So when you just type a.out, the shell searches for a.out in /usr/bin, /usr/sbin etc. (i.e. all the directories that are configured in the PATH variable) and since it can't find it, it complains about it. When you type ./a.out, that is a fully qualified path and the shell looks in the current directory and finds a.out and runs it. If you look at my previous reply, you don't need to add squat to any bin file. All you're doing is adding . to the list of PATH directories to search (of course, it is not always a good idea to do this, especially for a root user account, as salem already explained before) and then if you type a.out, it will execute the one in the current directory.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    20
    Rep Power
    0
    Originally Posted by Scorpions4ever
    You just need to set your PATH variable to look at your current directory as well. The way to do this depends on what shell you are using:

    csh or tcsh (FreeBSD uses this by default):
    setenv PATH=${PATH}:.

    bash, sh, ksh (OpenBSD uses ksh by default):
    export PATH=${PATH}:.

    The . at the end of the line tells the shell to look in the current directory along with the list of other directories, when it looks for a program to run. Now you can run a.out without a ./ in front.

    Put that line in your .tcshrc or .kshrc or whatever and it'll be set for you automatically when you log in.



    i am running freebsd. i added this line to my .cshrc file: setenv PATH=${PATH}:. is that case sensitive? should first PATH be path? I now have two paths statements in the .cshrc file? is that ok? anyway when i tried it it came back and said a.out not found? any ideas what I might be fouling up?
  22. #12
  23. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,616
    Rep Power
    4247
    whoops, I screwed up the setenv syntax. It should be:
    setenv PATH ${PATH}:.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  24. #13
  25. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    20
    Rep Power
    0
    well like I said, I am running freebsd. but it turns out the shell is the bourne shell(sh). I don't know if that is default for free bsd or what, but that is what is coming up. in the .PROFILE file there is a path and I put .: at the beginning and it seems to work. If I took that out and added what you indicate below,would it work? I mean can you have two paths in there?
    do you know how you get freebsd to tell you what shell is on point and how you change shells?



    Originally Posted by Scorpions4ever
    whoops, I screwed up the setenv syntax. It should be:
    setenv PATH ${PATH}:.
  26. #14
  27. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    20
    Rep Power
    0
    Do you understand what Salem is putting down? Please explain if you do. thanks



    Originally Posted by web9452
    well like I said, I am running freebsd. but it turns out the shell is the bourne shell(sh). I don't know if that is default for free bsd or what, but that is what is coming up. in the .PROFILE file there is a path and I put .: at the beginning and it seems to work. If I took that out and added what you indicate below,would it work? I mean can you have two paths in there?
    do you know how you get freebsd to tell you what shell is on point and how you change shells?
  28. #15
  29. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,616
    Rep Power
    4247
    Originally Posted by web9452
    well like I said, I am running freebsd. but it turns out the shell is the bourne shell(sh). I don't know if that is default for free bsd or what, but that is what is coming up. in the .PROFILE file there is a path and I put .: at the beginning and it seems to work. If I took that out and added what you indicate below,would it work? I mean can you have two paths in there?
    do you know how you get freebsd to tell you what shell is on point and how you change shells?
    Ok if you are using the Bourne shell, then you should use the export command I posted above, or simply add to the path as you gave done. The export command could also be added below, as what it does is say "take the existing path and add . to it" so you could have multiples of it sitting in the profile file.

    As for figuring out who uses what shell, you could cat /etc/passwd and see it there. You can change shells with the chsh command.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo