How apply command to file on $PATH with spaces?
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
My $PATH has /a/path/with spaces/in/it
I can run executables that sit on said path by simply typing their names.
But when I attempt to apply commands on them, they fail with can't be found error.
eg. I have a python script on the path, called prog.py
If I just type prog.py, my shell attempts to run it. So the path is working. But:
$ python3 prog.py
python3: can't open file 'prog.py': [Errno 2] No such file or directory
$ file prog.py
prog.py: cannot open `prog.py' (No such file or directory)
If I cd to the actual location of prog.py, then attempt the same commands, they run as expected:
$ file ./prog.py
./prog.py: Python script, ASCII text executable
$ python3 ./prog.py
True
Why does this happen? And what can I do to execute these commands (particularly python3) from wherever I wish?
python path
add a comment |Â
up vote
0
down vote
favorite
My $PATH has /a/path/with spaces/in/it
I can run executables that sit on said path by simply typing their names.
But when I attempt to apply commands on them, they fail with can't be found error.
eg. I have a python script on the path, called prog.py
If I just type prog.py, my shell attempts to run it. So the path is working. But:
$ python3 prog.py
python3: can't open file 'prog.py': [Errno 2] No such file or directory
$ file prog.py
prog.py: cannot open `prog.py' (No such file or directory)
If I cd to the actual location of prog.py, then attempt the same commands, they run as expected:
$ file ./prog.py
./prog.py: Python script, ASCII text executable
$ python3 ./prog.py
True
Why does this happen? And what can I do to execute these commands (particularly python3) from wherever I wish?
python path
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
My $PATH has /a/path/with spaces/in/it
I can run executables that sit on said path by simply typing their names.
But when I attempt to apply commands on them, they fail with can't be found error.
eg. I have a python script on the path, called prog.py
If I just type prog.py, my shell attempts to run it. So the path is working. But:
$ python3 prog.py
python3: can't open file 'prog.py': [Errno 2] No such file or directory
$ file prog.py
prog.py: cannot open `prog.py' (No such file or directory)
If I cd to the actual location of prog.py, then attempt the same commands, they run as expected:
$ file ./prog.py
./prog.py: Python script, ASCII text executable
$ python3 ./prog.py
True
Why does this happen? And what can I do to execute these commands (particularly python3) from wherever I wish?
python path
My $PATH has /a/path/with spaces/in/it
I can run executables that sit on said path by simply typing their names.
But when I attempt to apply commands on them, they fail with can't be found error.
eg. I have a python script on the path, called prog.py
If I just type prog.py, my shell attempts to run it. So the path is working. But:
$ python3 prog.py
python3: can't open file 'prog.py': [Errno 2] No such file or directory
$ file prog.py
prog.py: cannot open `prog.py' (No such file or directory)
If I cd to the actual location of prog.py, then attempt the same commands, they run as expected:
$ file ./prog.py
./prog.py: Python script, ASCII text executable
$ python3 ./prog.py
True
Why does this happen? And what can I do to execute these commands (particularly python3) from wherever I wish?
python path
asked Dec 6 '17 at 19:29
markling
606
606
add a comment |Â
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
2
down vote
accepted
This has nothing to do with the directory name containing spaces. When you run python3 prog.py
or file prog.py
, you're specifying a relative path, and standard Unix semantics mean that it will be opened from the current working directory. There's no sensible way to change that.
However, if you make the script executable (chmod +x /path/to/prog.py
) and ensure that it has a correct #!
line at the top (probably #! /usr/bin/python3
) then you will be able to execute it from anywhere by saying just prog.py
(not python3 prog.py
).
Incidentally, it's normally a good idea for programs on $PATH
not to contain an extension that specifies their implementation, since that's really a layering violation; I'd recommend calling it just prog
(replace as appropriate) rather than prog.py
.
add a comment |Â
up vote
2
down vote
I believe the issue is not with the space. Have you tried a path without a space?
The point is, $PATH
are the paths to look for executables, not files of random kind.
For example, if you have an executable that complains about a missing library, you have to use $LD_LIBRARY_PATH
to tell it where the file is. Adding the location of the file to $PATH
won't help. On the other hand if you come across a missing library in compile time, you need another variable (namely the $LIBRARY_PATH
).
So the best solution would be to add proper shebangs to your python scripts and put them somewhere in the $PATH
. If you want to be able to import them anywhere you need to work with $PYTHONPATH
.
add a comment |Â
up vote
0
down vote
It is how you are referencing the prog.py
file
python3 prog.py
says "in my current working directory there is a file named prog.py"
Your second example - where you use ./prog.py
- you are explicitly stating "in the current directory you'll find a program named prog.py"
Your $PATH is only searched for commands - not arugments to commands.
If you want to call the python binary (or any other binary like cat
or sed
or less
or ...) then it should be in your $PATH - which you seem to have. To reference any other file you must always supply a full relative path or full absolute path to the file.
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
This has nothing to do with the directory name containing spaces. When you run python3 prog.py
or file prog.py
, you're specifying a relative path, and standard Unix semantics mean that it will be opened from the current working directory. There's no sensible way to change that.
However, if you make the script executable (chmod +x /path/to/prog.py
) and ensure that it has a correct #!
line at the top (probably #! /usr/bin/python3
) then you will be able to execute it from anywhere by saying just prog.py
(not python3 prog.py
).
Incidentally, it's normally a good idea for programs on $PATH
not to contain an extension that specifies their implementation, since that's really a layering violation; I'd recommend calling it just prog
(replace as appropriate) rather than prog.py
.
add a comment |Â
up vote
2
down vote
accepted
This has nothing to do with the directory name containing spaces. When you run python3 prog.py
or file prog.py
, you're specifying a relative path, and standard Unix semantics mean that it will be opened from the current working directory. There's no sensible way to change that.
However, if you make the script executable (chmod +x /path/to/prog.py
) and ensure that it has a correct #!
line at the top (probably #! /usr/bin/python3
) then you will be able to execute it from anywhere by saying just prog.py
(not python3 prog.py
).
Incidentally, it's normally a good idea for programs on $PATH
not to contain an extension that specifies their implementation, since that's really a layering violation; I'd recommend calling it just prog
(replace as appropriate) rather than prog.py
.
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
This has nothing to do with the directory name containing spaces. When you run python3 prog.py
or file prog.py
, you're specifying a relative path, and standard Unix semantics mean that it will be opened from the current working directory. There's no sensible way to change that.
However, if you make the script executable (chmod +x /path/to/prog.py
) and ensure that it has a correct #!
line at the top (probably #! /usr/bin/python3
) then you will be able to execute it from anywhere by saying just prog.py
(not python3 prog.py
).
Incidentally, it's normally a good idea for programs on $PATH
not to contain an extension that specifies their implementation, since that's really a layering violation; I'd recommend calling it just prog
(replace as appropriate) rather than prog.py
.
This has nothing to do with the directory name containing spaces. When you run python3 prog.py
or file prog.py
, you're specifying a relative path, and standard Unix semantics mean that it will be opened from the current working directory. There's no sensible way to change that.
However, if you make the script executable (chmod +x /path/to/prog.py
) and ensure that it has a correct #!
line at the top (probably #! /usr/bin/python3
) then you will be able to execute it from anywhere by saying just prog.py
(not python3 prog.py
).
Incidentally, it's normally a good idea for programs on $PATH
not to contain an extension that specifies their implementation, since that's really a layering violation; I'd recommend calling it just prog
(replace as appropriate) rather than prog.py
.
answered Dec 6 '17 at 19:54
Colin Watson
2,444128
2,444128
add a comment |Â
add a comment |Â
up vote
2
down vote
I believe the issue is not with the space. Have you tried a path without a space?
The point is, $PATH
are the paths to look for executables, not files of random kind.
For example, if you have an executable that complains about a missing library, you have to use $LD_LIBRARY_PATH
to tell it where the file is. Adding the location of the file to $PATH
won't help. On the other hand if you come across a missing library in compile time, you need another variable (namely the $LIBRARY_PATH
).
So the best solution would be to add proper shebangs to your python scripts and put them somewhere in the $PATH
. If you want to be able to import them anywhere you need to work with $PYTHONPATH
.
add a comment |Â
up vote
2
down vote
I believe the issue is not with the space. Have you tried a path without a space?
The point is, $PATH
are the paths to look for executables, not files of random kind.
For example, if you have an executable that complains about a missing library, you have to use $LD_LIBRARY_PATH
to tell it where the file is. Adding the location of the file to $PATH
won't help. On the other hand if you come across a missing library in compile time, you need another variable (namely the $LIBRARY_PATH
).
So the best solution would be to add proper shebangs to your python scripts and put them somewhere in the $PATH
. If you want to be able to import them anywhere you need to work with $PYTHONPATH
.
add a comment |Â
up vote
2
down vote
up vote
2
down vote
I believe the issue is not with the space. Have you tried a path without a space?
The point is, $PATH
are the paths to look for executables, not files of random kind.
For example, if you have an executable that complains about a missing library, you have to use $LD_LIBRARY_PATH
to tell it where the file is. Adding the location of the file to $PATH
won't help. On the other hand if you come across a missing library in compile time, you need another variable (namely the $LIBRARY_PATH
).
So the best solution would be to add proper shebangs to your python scripts and put them somewhere in the $PATH
. If you want to be able to import them anywhere you need to work with $PYTHONPATH
.
I believe the issue is not with the space. Have you tried a path without a space?
The point is, $PATH
are the paths to look for executables, not files of random kind.
For example, if you have an executable that complains about a missing library, you have to use $LD_LIBRARY_PATH
to tell it where the file is. Adding the location of the file to $PATH
won't help. On the other hand if you come across a missing library in compile time, you need another variable (namely the $LIBRARY_PATH
).
So the best solution would be to add proper shebangs to your python scripts and put them somewhere in the $PATH
. If you want to be able to import them anywhere you need to work with $PYTHONPATH
.
answered Dec 6 '17 at 19:53
Weijun Zhou
1,434119
1,434119
add a comment |Â
add a comment |Â
up vote
0
down vote
It is how you are referencing the prog.py
file
python3 prog.py
says "in my current working directory there is a file named prog.py"
Your second example - where you use ./prog.py
- you are explicitly stating "in the current directory you'll find a program named prog.py"
Your $PATH is only searched for commands - not arugments to commands.
If you want to call the python binary (or any other binary like cat
or sed
or less
or ...) then it should be in your $PATH - which you seem to have. To reference any other file you must always supply a full relative path or full absolute path to the file.
add a comment |Â
up vote
0
down vote
It is how you are referencing the prog.py
file
python3 prog.py
says "in my current working directory there is a file named prog.py"
Your second example - where you use ./prog.py
- you are explicitly stating "in the current directory you'll find a program named prog.py"
Your $PATH is only searched for commands - not arugments to commands.
If you want to call the python binary (or any other binary like cat
or sed
or less
or ...) then it should be in your $PATH - which you seem to have. To reference any other file you must always supply a full relative path or full absolute path to the file.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
It is how you are referencing the prog.py
file
python3 prog.py
says "in my current working directory there is a file named prog.py"
Your second example - where you use ./prog.py
- you are explicitly stating "in the current directory you'll find a program named prog.py"
Your $PATH is only searched for commands - not arugments to commands.
If you want to call the python binary (or any other binary like cat
or sed
or less
or ...) then it should be in your $PATH - which you seem to have. To reference any other file you must always supply a full relative path or full absolute path to the file.
It is how you are referencing the prog.py
file
python3 prog.py
says "in my current working directory there is a file named prog.py"
Your second example - where you use ./prog.py
- you are explicitly stating "in the current directory you'll find a program named prog.py"
Your $PATH is only searched for commands - not arugments to commands.
If you want to call the python binary (or any other binary like cat
or sed
or less
or ...) then it should be in your $PATH - which you seem to have. To reference any other file you must always supply a full relative path or full absolute path to the file.
answered Dec 6 '17 at 19:54
ivanivan
3,1281213
3,1281213
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f409284%2fhow-apply-command-to-file-on-path-with-spaces%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password