Results 1 to 6 of 6

Thread: Run a compiled executable default?

  1. #1
    Join Date
    Apr 2011
    Beans
    3

    Run a compiled executable default?

    Hi everyone!

    I'm using intel fortran and c++ compilers on Ubuntu. When the code is compiled it spits out an executable.

    Question:
    Is it possible to tell the terminal to execute such a file by just writing it's name, without the './" ? (Right now it gives me a command-not-found error.)

    Or at least associate some extension, like '.exe' to make them executable?


    P.S. I know - I'm just being lazy. I never bothered with such a thing, until I started using a cluster at uni, which has some version of Ubuntu installed. And it runs these files without the "./" via ssh.

  2. #2
    Join Date
    Mar 2010
    Beans
    Hidden!

    Re: Run a compiled executable default?

    Quote Originally Posted by oznick View Post
    Hi everyone!

    I'm using intel fortran and c++ compilers on Ubuntu. When the code is compiled it spits out an executable.

    Question:
    Is it possible to tell the terminal to execute such a file by just writing it's name, without the './" ? (Right now it gives me a command-not-found error.)

    Or at least associate some extension, like '.exe' to make them executable?


    P.S. I know - I'm just being lazy. I never bothered with such a thing, until I started using a cluster at uni, which has some version of Ubuntu installed. And it runs these files without the "./" via ssh.
    If you create a folder in your home folder and call it "bin" (without the quotes), logout and log back in. The ~/bin folder is in the system path. So dropping any executable (marked as executable in "Properties") in the new folder will allow its execution from terminal with just its name.

    To check your system path use in terminal
    Code:
    echo $PATH
    To add other folders to your system path you can use the export command in ~/.profile.

    an example from my ~/.profile file for the purpose of including 5 subfolders of ~/bin in the system path,

    Code:
    # set PATH so it includes user's private bin if it exists
    if [ -d "$HOME/bin" ] ; then
        PATH="$PATH:$HOME/bin"
    fi
    
    export PATH=$PATH:$HOME/bin/chroot
    export PATH=$PATH:$HOME/bin/MyScripts
    export PATH=$PATH:$HOME/bin/Radio
    export PATH=$PATH:$HOME/bin/System
    export PATH=$PATH:$HOME/bin/UDF
    Any scripts or programs dropped into the above 5 custom folders are useable from terminal by their names alone (if also marked as executable in their Properties).

  3. #3
    Join Date
    Apr 2011
    Beans
    3

    Re: Run a compiled executable default?

    Okay, got it. But it is possible export the current directory you are cd'ed in, instead of dropping files to a certain folder?

  4. #4
    Join Date
    Mar 2010
    Beans
    Hidden!

    Re: Run a compiled executable default?

    Quote Originally Posted by oznick View Post
    Okay, got it. But it is possible export the current directory you are cd'ed in, instead of dropping files to a certain folder?
    You would need that folder put in the system path using the info about ~/.profile.

    If you use the code to check out your current system path, your will notice only a handful of locations are there. I suspect putting too many folders in the system path may not be a good idea for stability or possibly even security reasons.

    Edit: try using in the terminal (for a temporary path change) the code (adjust it to the folder you want)
    Code:
    export PATH=$PATH:/<your-folders-full-location-path>
    On the next logout or reboot the path will return to normal.
    Last edited by yetiman64; April 13th, 2011 at 08:32 AM.

  5. #5
    Join Date
    Apr 2011
    Beans
    3

    Re: Run a compiled executable default?

    But what if you remove the folder from the system path as soon as you cd out of it? Or does the list only get updated on terminal login?

  6. #6
    Join Date
    Mar 2010
    Beans
    Hidden!

    Re: Run a compiled executable default?

    Quote Originally Posted by oznick View Post
    But what if you remove the folder from the system path as soon as you cd out of it? Or does the list only get updated on terminal login?
    If you are talking about the temporary solution using the export command in terminal (my edit) it will only stick till the next logout. If you refer to the ~/.profile entries, they are permanent entries regenerated on each login.

    AFAI understand it, to launch a script or program from terminal using just its name requires the script or program to be in the system path.
    Last edited by yetiman64; April 13th, 2011 at 08:40 AM. Reason: typo

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •