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 ?
    – Dadep
    CommentedAug 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.
    – Matt Cree
    CommentedAug 21, 2017 at 17:30
  • 1
    hint: PATH...
    – twalberg
    CommentedAug 21, 2017 at 17:31
  • See this answerCommentedAug 21, 2017 at 17:33
  • I wouldn't worry about being too picky for someone who uses cat input.txt | program ... as an example.
    – chepner
    CommentedAug 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 
5
  • 1
    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.
    – chepner
    CommentedAug 21, 2017 at 19:16
  • I've added some more info.
    – Matt Cree
    CommentedAug 21, 2017 at 21:20
  • Try linking to the full path
    – Egal
    CommentedAug 21, 2017 at 21:23
  • Do these links persist between sessions? Or is it transient?
    – Matt Cree
    CommentedAug 21, 2017 at 21:29
  • It's persistent as your filesystem. So for a regular laptop/desktop installation the answer is yes.
    – Egal
    CommentedAug 21, 2017 at 21:59

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.