0

I'm being asked to make a python program that parses tokens.

The usage is as follows:

$ cat input.txt | program "some text %{0} and %{1S3}" > output.txt

but the best I can manage is:

$ cat input.txt | py program.py "some text %{0} and %{1S3}" > output.txt

or if I make the script executable, remove the file extension, and I'm in the current directory

$ cat input.txt | ./program "some text %{0} and %{1S3}" > output.txt

Is there a way for me to use the first example's style of execution with a python script? Ideally I'd also be able to use it from anywhere, not necessary when pointing at the directory containing the program.

Edit: I've tried this:

Here's what I tried --

$ cd projects/token_parser/
$ ln -s grap /usr/local/bin/grap
ln: failed to create symbolic link '/usr/local/bin/grap': Permission denied
$ sudo ln -s grap /usr/local/bin/grap 
[sudo] password for fosssaintdross: 
$ grap
bash: grap: command not found
5
  • why don't you just read and write file from your python script ? Commented Aug 21, 2017 at 17:25
  • It's a code audition for an interview so I'm trying to match their spec as closely as possible. Commented Aug 21, 2017 at 17:30
  • 1
    hint: PATH... Commented Aug 21, 2017 at 17:31
  • See this answer Commented Aug 21, 2017 at 17:33
  • I wouldn't worry about being too picky for someone who uses cat input.txt | program ... as an example. Commented Aug 21, 2017 at 19:17

1 Answer 1

2

You need to make sure the location containing program.py is in the PATH environment variable. Alternatively you can link to it from a path that is already in the list, for example:

ln -s /path/to/program.py /usr/local/bin/program
Sign up to request clarification or add additional context in comments.

5 Comments

If you actually have write access to /usr/local, it's typically a far better idea to do a proper installation, rather than throwing arbitrary symlinks in to /usr/local/bin.
I've added some more info.
Try linking to the full path
Do these links persist between sessions? Or is it transient?
It's persistent as your filesystem. So for a regular laptop/desktop installation the answer is yes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.