Is it possible to modify bash to run one command through another (say a python script)?

6

1

I was wondering if it is possible to modify bash such that when I type

command --arg1

what actually happens is

~/prerun.py command --arg1

(prerun.py would handle starting command --arg1 itself)

Thanks!

Jake Burton

Posted 2012-10-07T20:53:03.243

Reputation: 163

Answers

5

command () {
    prerun.py some_command $@
}

Then when you run command --arg1 it will pass it all on to the prerun.py script.

UtahJarhead

Posted 2012-10-07T20:53:03.243

Reputation: 1 755

Note that a function is recommended above an alias for extensibility purposes. Passing it variables and whatnot are far more capable. They can be multiple lines long and allow you to use variables internally. – UtahJarhead – 2012-10-07T21:50:36.323

2make sure you quote "$@" so any arguments with whitespace are protected – glenn jackman – 2012-10-08T02:00:07.837

6

Define an alias with the alias builtin:

alias command='~/prerun.py command'

Gilles 'SO- stop being evil'

Posted 2012-10-07T20:53:03.243

Reputation: 58 319