pgb*_*blu 2 ruby .bash-profile
我希望能够在ruby程序中调用我的一个快捷方式(即别名).换句话说,我想要
system('cpl')
Run Code Online (Sandbox Code Playgroud)
相当于写作
cd ~/Documents/CPlusPlus
Run Code Online (Sandbox Code Playgroud)
在命令行,因为我.bash_profile包括该行
alias cpl="cd ~/Documents/cplusplus"
Run Code Online (Sandbox Code Playgroud)
我在Mac OSX上,当我.bash_profile住在通常的地方(~)时,我可能会在任何旧文件夹中写入ruby.我正在使用位于的Ruby 2.2.0 /usr/local/bin/ruby.
以下应该有效:
system("bash -ci 'cpl'")
Run Code Online (Sandbox Code Playgroud)
该c开关通知"执行" cpl的命令,而不是搜索文件.该i转弯打坏成互动模式,更重要的是加载.bashrc文件.
编辑:确保在.bashrc文件中定义别名.每个新shell初始化时都会加载此文件.该.bash_profile只装载在每次用户登录.在这里查看更多.