I'd like to be able to call one of my shortcuts (i.e., aliases) from within a ruby program. In other words, I want
system('cpl')
to be the equivalent of writing
cd ~/Documents/CPlusPlus
at the command line, because my .bash_profile
includes the line
alias cpl="cd ~/Documents/cplusplus"
I'm on a Mac OSX, and while my .bash_profile
lives in the usual place (~
), I might be writing ruby in/to any old folder. I am using Ruby 2.2.0 which is located in /usr/local/bin/ruby
.
From
source
docs:From
shopt -s expand_aliases
docs:You use non-interactive shell, so this additional step is required:
The following should work:
The
c
switch tells to "execute"cpl
as a command instead of searching for a file. Thei
turns bash into interactive mode and more importantly loads the.bashrc
file.EDIT: Make sure you define your alias in the
.bashrc
file. This file is loaded every a new shell initializes. The.bash_profile
is only loaded upon every user login. See more here.