简体   繁体   中英

Running a python command line utility

So I finished writing a Python program that handles some sample banking info.

I was told to create a makefile for the assignment that will have build,view and clean targets. I've gotten that much done and it works as anticipated.

However, I was told that my instructor would run the program similar to

accounts -i

where accounts is the program and -i is the arg.

However, I have only been able to use

./accounts -i

to run the program.

I looked around and I found something about adding the file to PATH but I am really lost as to what I am doing. Is there something wrong on my end or is my instructor telling me to do something wrong?

Thanks.

You can add . (the current working directory) to your path with something like (bash/ksh syntax) :

export PATH="$PATH:."

...but this is widely regarded as a security problem.

You're probably best off just typing ./accounts -i. Your instructor will probably already know the issue.

Personally, I would imagine that this was just a simple typo or something like it by your instructor.

In shell scripting, the PATH variables denotes a set of directories (separated by colons) that will be searched for the executable that you are referencing.

So assuming your PATH is equal to ".:/usr/bin", when you type "accounts -i" at the command line, your shell with first search for "./accounts" and then (assuming it does not exist) check for "/usr/bin/accounts". If it finds either it will then execute the one that exists and pass the given arguments (ie "-i").

If you would like to try this out, PATH is generally modified like this:

export PATH="directory_name:$PATH"

(as it is most likely that you will be wanting to have "directory_name" take precedence over the rest of what is current in $PATH).

However, "." is generally not included in PATH by default, which is considered to be bad practice by many for reasons detailed here .

So my guess is your instructor either has "." in his or her PATH, or will quickly realize that using "./acccounts" is more appropriate.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM