1

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

Use a shell function:

build() { command build "$@"; beep; }

To make this function permanent, add it to ~/.bashrc.

  • 1
    Thanks. 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. – Aidenator Jun 16 '16 at 18:25
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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