473,749 Members | 2,665 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Run a python script and the #!/usr/bin/python line

7 New Member
I'm coming from the MSW development world and a few things in linux/ubuntu for "getting things done" have got me stumped.

If I have my python app in "/usr/local/pyscripts" named "myapp.py", how can I set up things so that I can run it from anywhere on the command line by simply giving the command "myapp arg1 arg2 arg3" ? (I can write bash scripts and set aliases if necessary.)

What (good) is the shebang line for in Python scripts ? What part of the OS uses it ?

TIA :-)
Jul 7 '12
15 2866
numberwhun
3,509 Recognized Expert Moderator Specialist
If you would like to know the reasoning behind why dot is a bad thing to have in the PATH variable, then read this.

As per the article, if you do decide to add it to your path, only add it at the end and not the beginning of the PATH variable. You could simply put this in your .bashrc and open another window:

Expand|Select|Wrap|Line Numbers
  1. PATH = $PATH:.
  2.  
But know that myself and probably most other unix people here are just fine with putting the ./ before our scripts. We don't find it to be an issue because:

#1. We know the security risks behind it and
#2. Most importantly, this isn't a Windows system. Windows is insecure (IMHO) because of its lax nature of how it does things. You aren't going to make this Windows and are just going to have to deal with the nuances of it. They are there for a reason.

Regards,

Jeff
Jul 31 '12 #11
pascor
7 New Member
Security (and the lack there of) and the OS getting programs in PATH mixed up generally have nothing to do with each other.

This forum isn't the place to flame Windows security issues. There are plenty of other places to do that.
Jul 31 '12 #12
numberwhun
3,509 Recognized Expert Moderator Specialist
Believe me, I wasn't flaming Windows, I was pointing out what, in my opinion, is a fact. You made the comparison to Windows in post #5 above, I just added an observation to it.

Further to that, we definitely need to get the point across that searching the current directory first is extremely insecure and should not be done. Personally I would stick to using the ./ in front o things, and always do, versus adding the current directory to my path. Don't learn that lesson the hard way, it can wreak havoc.
Aug 1 '12 #13
Mariostg
332 Contributor
Really pascor how much time did you spent researching about your problem? Did you even bother looking at the links that were provided to you? I sincerely believe all replies provided to your queries are fair. There are several exemples on the internet about the nasty things that could happen if you set your current directory in the path. As @Numberwhun
said, if you want it in your path, put it last. It is a wise advise.
Aug 1 '12 #14
pascor
7 New Member
The security issues amount to just 2 potential problems:

1 - If a user is stupid enough to name a program the same as an already existing program or script name. This implies the user is only slightly smarter than a head of cabbage and doesn't first use the [ which ] utility to avoid name duplications.

2 - If the system is hacked. This implies that the OS is inherently unsafe, anyway, and much more anti-malware protection is needed.

Since I'm not a professional developer, I think the risks are minimal.
Aug 1 '12 #15
numberwhun
3,509 Recognized Expert Moderator Specialist
They would not have the security warnings against something if it wasn't a concern. You would think that people wouldn't do it, but it happens. Heck, people alias things all the time and get themselves in trouble without even knowing it. Users are the inherent threat that all sys admins guard against, its just the way things go. Doesn't matter the OS, the user is the reason for rules most of the time.

I am not going to go any further with this. You have been given the articles to read on the security risks and the system you are working on is yours. If you take the risk then you have nobody to blame but yourself if something goes wrong. We can only give you advice.

Regards,

Jeff
Aug 1 '12 #16

Sign in to post your reply or Sign up for a free account.

Similar topics

10
3487
by: Noah | last post by:
I would like to package my main script and all the modules it imports into a single script that will run just as the collection would. It should not need to package standard Python lib modules -- just my local modules. This is not the same question that would be answered with py2exe or py2app. I don't need to package the script into a binary along with Python. I expect Python to be installed. I also don't want to use distutils to install...
1
1751
by: michael.buonomo | last post by:
We have been using the Google recommended python script for about a year. We recently realized that the script was not crawling our sites url's, but just our folders which reside on the server. The python script seems to be designed for 'non database' sites, not a site which is using .asp, and has dynamic pages. We are an ecommerce site. What are other ecommerce sites using to create an xml file? Are they using the python script?
3
1691
by: CarlP | last post by:
How do I run a Python script. I have one that gmail loader needs to run on my email box. Here's the script http://www.marklyon.org/gmail/cleanmbox.py I can't seem to find what I need to run it. I installed python, run the interpreter and the script , but all it will do is say invalid syntax.
1
2432
by: sophie_newbie | last post by:
Hi, I'm running a python script which if I run from the command line as root runs fine. But if I run it through the web-browser as a cgi script gives the following error "Error in X11: unable to start device PNG". Now I should say that this python script is calling fucntions in R (a scripting languange used in statistics) using the python module RPy, so this I dunno if this is entirely a Python question, because as far as I can see the...
4
2833
by: Chris8Boyd | last post by:
I am embedding Python in a MSVC++ (2005) application. The application creates some environment and then launches a Python script that will call some functions exported from the MSVC++ application. I want to be able to debug the Python script by using a debug server, like Winpdb (winpdb.org). I use ActivePython 2.5.2.2, Microsoft Visual Studio 2005, and Winpdb 1.3.8.
4
3092
by: Chris Seymour | last post by:
Hi All, I am working on a python script for my colleague that will walk a directory and search in the different files for a specific string. These pieces I am able to do. What my colleague wants is that when she runs the script the filename is replaced by the current file that is being processed. So instead of seeing a series of files being listed down the page, she only wants to see the file currently being processed. I am not sure...
1
3583
by: hofsoc20 | last post by:
Hi, I am trying to call a python script (Python 2.5) and implement one of its functions. I have successfully called the script and executed it with jep.runscript("sample.py"). Does anyone know how I can call individual functions within the python script? Thanks in advance...
6
31149
by: mott3510 | last post by:
I wrote a python script and I have copied my file (verification.py) into my http directory. However, when I try to run the script I get many errors... .. : No such file or directoryline 1: #!/usr/bin/python : command not foundect.py: line 3: ./Verification_Project.py: line 4: from: command not found : command not foundect.py: line 5: ./Verification_Project.py: line 6: from: command not found import: unable to open X server `'. import:...
2
4753
by: gintrado | last post by:
I am very new to Python I'm trying to run a python script from within another python script. I can run the script from a unix command line by typing: nohup python script.py password > /tmp/outfile.log 2>&1 & Or, I can put that command in a shell script and run it by typing: ./script.sh Both work great. However I don't know how to put either the command or the shell script in a python.py script and get it to run from there. Let me...
0
1781
by: Stef le Breton | last post by:
Hi, I need to compile a pyhton tool into an executable as the destination plateform (Solaris, Linux) are not deployed with Python or not all needed modules. I found pyinstaller and follow the classical tutorial. First executable starts correctly under Linux but not under windows. Second it crashes right after due to unknown module that haev to be loaded.
0
8833
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9568
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9335
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9256
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8257
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6079
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3320
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2794
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2218
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.