Artificial intelligent assistant

How to define similar bash function at once 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? _environment_ bash --version GNU bash, version 3.2.51(1)-release (x86_64-apple-darwin13)

$ cat t.sh
#!/bin/bash

for func in guard rspec rake; do
eval "
${func}() {
local foo=(command ${func})
[ -e 'Gemfile' ] && foo=(bundle exec ${func})
\"\${foo[@]}\" \"\$@\"
}
"
done

type guard rspec rake


.


$ ./t.sh
guard is a function
guard ()
{
local foo=(command guard);
[ -e 'Gemfile' ] && foo=(bundle exec guard);
"${foo[@]}" "$@"
}
rspec is a function
rspec ()
{
local foo=(command rspec);
[ -e 'Gemfile' ] && foo=(bundle exec rspec);
"${foo[@]}" "$@"
}
rake is a function
rake ()
{
local foo=(command rake);
[ -e 'Gemfile' ] && foo=(bundle exec rake);
"${foo[@]}" "$@"
}


The usual cautions about `eval` apply.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 37213c719548b1b693e5d6ce50e153f5