Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Executing Files in Terminal

  1. #1
    Join Date
    Feb 2009
    Beans
    46

    Executing Files in Terminal

    There is an executable file that I can double-click to execute in the File Browser and it runs like expected.

    But when I try to execute the file in the Terminal window it doesn't work because it says "command not found".

    The file name is four words long separated by spaces. I tried enclosing the file name in double and single quotes. I even copied and pasted the file name so I know that I am not typing it incorrectly.

    I assume this is a syntactical problem. Any help?

  2. #2
    Join Date
    Dec 2007
    Location
    United States
    Beans
    2,900
    Distro
    Ubuntu

    Re: Executing Files in Terminal

    You can attempt to run it with back slashes before the spaces:

    Code:
     ./a\ file\ with\ spaces

  3. #3
    Join Date
    May 2009
    Beans
    109
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: Executing Files in Terminal

    Are you in the right directory?

  4. #4
    Join Date
    Dec 2007
    Location
    United States
    Beans
    2,900
    Distro
    Ubuntu

    Re: Executing Files in Terminal

    Note the "./" in front of my sample command implies you are "there" as in the directory that contains the file you want to run. Otherwise you could enter a full path as in /full/path/to/my/file\ with\ a\ space

  5. #5
    Join Date
    Apr 2007
    Beans
    402
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Executing Files in Terminal

    In summary:

    To reference a file with spaces in the name, you can enclose the file with quotes

    "just like this"

    or escape the space with a backslash

    just\ like\ this


    Note that Linux works differently than Windows. When you type a filename in the terminal, it doesn't always by default look in the current working directory; it looks in the path.

    You can view the current path by typing:

    Code:
    echo $PATH
    In order to access a file in the current directory, prepend a dot-slash to the front of the filename, thusly:

    ./file

    It takes a bit of getting used to at first, especially when coming from a Windows background.

  6. #6
    Join Date
    Nov 2008
    Location
    Here, There, Everywhere
    Beans
    1,166
    Distro
    Xubuntu

    Re: Executing Files in Terminal

    you can also use the interpreter executable like
    Code:
    sh myscript.sh
    or
    Code:
    python myscript.py

  7. #7
    Join Date
    May 2009
    Beans
    109
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: Executing Files in Terminal

    Or, you can add the directory the file is in to your path by adding the following to your .bash_profile.

    Code:
    export PATH=$PATH:directory_name

  8. #8
    Join Date
    Feb 2009
    Beans
    46

    Re: Executing Files in Terminal

    Quote Originally Posted by ecmatter View Post
    Are you in the right directory?
    Yes, I'm in the right directory.

  9. #9
    Join Date
    Feb 2009
    Beans
    46

    Re: Executing Files in Terminal

    Wow, thanks for all the suggestions everyone. I took the direct approach to this and followed Volt9000's instructions. I typed ./"file with spaces" and it ran.

  10. #10
    Join Date
    Oct 2006
    Location
    Lyon, France
    Beans
    839
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Executing Files in Terminal

    You could have tried tab-completion.

    Just type ./first_few_letters_to_your_executable, press TAB, and the name will be completed as far as the shell can guess. This includes special characters, so spaces are escaped with backslashes, etc.
    This is the first age that's paid much attention to the future, which is a little ironic since we may not have one.
    -- Arthur C. Clarke

Page 1 of 2 12 LastLast

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
  •