I have these functions in ~/.bashrc:function guard() {    if [ -e 'Gemfile' ]; then    bundle exec guard $@    else    command guard $@    fi}function rspec() {    if [ -e 'Gemfile' ]; then    bundle exec rspec $@    else    command rspec $@    fi}function rake() {    if [ -e 'Gemfile' ]; then        bundle exec rake $@    else        command rake $@    fi}As you see these functions are very similar. I want to define these 3 functions at once. Is there a way to make it?environmentbash --versionGNU bash, version 3.2.51(1)-release (x86_64-apple-darwin13)
How to define similar bash function at once
bash
$ cat t.sh#!/bin/bashfor func in guard rspec rake; do        eval         ${func}() {                local foo=(command ${func})                [ -e 'Gemfile' ] && foo=(bundle exec ${func})                \\${foo[@]}\ \\$@\        }        donetype guard rspec rake.$ ./t.shguard is a functionguard (){    local foo=(command guard);    [ -e 'Gemfile' ] && foo=(bundle exec guard);    ${foo[@]} $@}rspec is a functionrspec (){    local foo=(command rspec);    [ -e 'Gemfile' ] && foo=(bundle exec rspec);    ${foo[@]} $@}rake is a functionrake (){    local foo=(command rake);    [ -e 'Gemfile' ] && foo=(bundle exec rake);    ${foo[@]} $@}The usual cautions about eval apply.