I'm using Bash. I have a build command that I run a few times a day. I also have a command called "beep" that I use to alert me when a command finishes. So normally I do "build arg1 arg2; beep" and it's fine. But sometimes I forget to append the "beep" command and I don't want to stop the build process just to append the "beep". Is there an easy way to always have the "beep" command appended after my "build" command in my .bashrc file? The arguments change for the build command so I can't just make a static alias for it unfortunately. I'm thinking I'll have to make a shell script for it, but I was wondering if there's a quicker way. Thanks.
2 Answers
Use a shell function:
build() { command build "$@"; beep; }
To make this function permanent, add it to ~/.bashrc
.
-
1Thanks. For some reason Bash didn't like the last semi-colon after beep, but when I removed it everything worked. I definitely like how it's on 1 line to keep my bashrc looking clean. Jun 16, 2016 at 18:25
One step up from an alias would be a function:
function b2 {
build "$@"
beep
}
Name it anything you want, and then call it with, for example: b2 arg1 arg2
.