swap shell commands

2

The command

python foo.py

When called on the terminal, it runs the sent python file. Imagine that I have a python file that always needs to be called as follows:

xvfb-run python foo.py

to work.

Is there any way I can write something like this in Shell:

python = xvfb-run python

So, whenever I call python it will call xvfb-run python ?

    
asked by anonymous 27.05.2015 / 14:40

2 answers

4

I do not know if you can assign something to the word python , in specific. It should be tied to the binaries of python and should be somewhat complicated to change. What I know is that you can create a alias for your command, something like

$ alias meu_comando = 'xvfb-run python'

The usage would be $ meu_comando foo.py . Read about alias here

EDIT:

According to this link:

  

An alias can be created with the same name as the core name of a command (i.e., a command without any options or arguments). In such case, it is the alias that is called (i.e., activated) first when the name is used, rather than the command with the same name.

So you can do what you want. I just do not know if it's a good idea ...

    
27.05.2015 / 14:52
1

An alias would solve your problem, but if it does not resolve, develop another python file that will call the file you need.

bar.py import subprocess subprocess.call("xvfb-run python foo.py")

Then call your file with the created command $python bar.py

But reinforcement that Alias would be a better alternative.

    
27.05.2015 / 15:36