Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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!

share|improve this question
add comment

2 Answers

up vote 5 down vote accepted
command () {
    prerun.py some_command $@
}

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

share|improve this answer
    
Thanks! Exactly what I was looking for. –  Jake Burton Oct 7 '12 at 21:10
    
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 Oct 7 '12 at 21:50
2  
make sure you quote "$@" so any arguments with whitespace are protected –  glenn jackman Oct 8 '12 at 2:00
add comment

Define an alias with the alias builtin:

alias command='~/prerun.py command'
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.