Aliases are mostly useful when you want to shorten part of a commonly used command which takes variable arguments. In a ruby dev context that might be creating an alias like
alias be="bundle exec"
because who wants to type out
bundle exec all the time?
If what you really want is a shorter version of a longer command with static arguments then you should create a script anyway. With a script, it will always be available and not be dependent on sourcing particular profiles in particular contexts (which you can basically never rely on).
A more comman case (like that above) is when you use an alias because you want to effortless string arguments on to the end of the alias. For instance
$ be rails server
$ be rake db:migrate
In both cases, i don't want to have to type out more than I need to. With just a dash of bash, however, you can achieve the same thing in a more versatile solution.
Similar to some of the above answers, create a file -
/usr/local/bin/be in this example. This assumes that
/usr/local/bin is included in your
bundle exec "$@"
followed up with (possibly with
$ chmod +x /usr/local/bin/be
This is a bit of a naive example, and requires that both
ruby and the
bundler gem have been installed, but the thing to notice is
"$@" which let's you pass in a variable number of arguments into the script. Thus, you get the ergonomics of the alias, but with a command that is always available and not context dependent.
I find this approach particularly helpful when working with containers. Hope it helps.