|
||||||
| Forums FAQ | Members List | Search | Today's Posts | Mark Forums Read |
| ARCHIVES - General Questions If your question doesn't fit in any other category below ask in here. |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Hi.
I have a problem that for executing python script in bash, I need to type: > python myfile.py because in no other way it starts Also for the shell scripts, I must do > sh myscript.sh How to make it run by just typting the file name? (both shell and python) I always put in python script as a first line: #!/usr/bin/env python and for shell: #!/bin/sh Where is the catch? Thanks! |
|
|||
|
You mean just typing the file directly, regardless the current position?
Then you need to place the file in your PATH variable, Code:
echo $PATH The most simple way is to place your script in the ~/bin directory. You can also symbolic link it. It has already added in PATH variable. Don't forget to give the execute permission. Oh yeah, just some tips. You may consider to give your script different naming convention, for example all caps or just the first character of file are caps, to avoid conflict with the system command which usually using small character. |
|
|||
|
Thanks.
Yes, I did put it in my script directory and put it in path. I found, just now, that for shell scripts, I should put #! /bin/bash and add execute permissions. This is OK now. However, I cannot resolve python thing
|
|
|||
|
Try to change it to:
Code:
#!/usr/bin/python It's called preprocessor directive, if I'm not mistaken. |
|
|||
|
Quote:
i.e. ls -l myfile.py Are the execute permissions set? |
|
|||
|
Quote:
The #!/.... construction has nothing to do with any preprocessing. It is the way to tell the shell (where you type the command to start the script) which interpreter to start. Somewhere the system must know if this is a bash, python, php or whatever script. The #!/... is sometimes called the shebang (there are other nicknames). Read Wikipedia. |
|
|||
|
I found that for some reason, gedit puts some strange character when you press enter. Something like windows' #13#10
now works. Thank you all |
|
|||
|
Use bash -x when trouble shooting how I found out last time you did this
![]() So if ./file doesn't work execute it as bash -x ./file then you'll get hopefully some useful feedback. |
|
|||
|
Quote:
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|