swap commands in the shell

Asked

Viewed 106 times

2

The command

python foo.py

When called on the terminal, it runs the uploaded 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 he’ll call xvfb-run python?

2 answers

4


I don’t know if you can assign something to the word python, in particular. It must be tied to python binaries and it must be kind of complicated to change. What I do know is that you can create a alias for your command, something like

$ alias meu_comando = 'xvfb-run python'

The use 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 a 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.

Therefore, you can do what you want. I just don’t know if it’s a good idea...

1

An alias would solve your problem, but if you don’t solve develop another python file that calls the following 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 reinforce that the Alias would be a better alternative.

  • I really liked to use the Mands but it was discontinued. https://docs.python.org/2/library/commands.html for python 3 
import commands
result = commands.getstatusoutput("xvfb-run python foo.py")



Browser other questions tagged

You are not signed in. Login or sign up in order to post.