View Full Version : [SOLVED] Executing Files in Terminal
GaretJax
May 27th, 2009, 11:04 PM
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?
blueridgedog
May 27th, 2009, 11:07 PM
You can attempt to run it with back slashes before the spaces:
./a\ file\ with\ spaces
ecmatter
May 27th, 2009, 11:09 PM
Are you in the right directory?
blueridgedog
May 28th, 2009, 01:18 AM
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
Volt9000
May 28th, 2009, 02:14 AM
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:
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.
Tibuda
May 28th, 2009, 02:28 AM
you can also use the interpreter executable like
sh myscript.sh
or
python myscript.py
ecmatter
May 28th, 2009, 02:46 AM
Or, you can add the directory the file is in to your path by adding the following to your .bash_profile.
export PATH=$PATH:directory_name
GaretJax
May 29th, 2009, 09:58 PM
Are you in the right directory?
Yes, I'm in the right directory.
GaretJax
May 29th, 2009, 10:06 PM
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.
Mornedhel
May 29th, 2009, 10:12 PM
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.
el.numbre
June 3rd, 2009, 07:33 PM
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:
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.
thanks that was really helpful :)
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.