On Sat, 9 Dec 2006, Chris Kilmer wrote: > I'm trying to build a script that automates the sourcing of multiple bash > alias files using ruby. I'm running into problems in that it while my alias > files get run, the terminal session doesn't recognize any of the aliases > that were set. > > I'll use a simple example to be more clear: > > My original .bash_rc originally looked like this: > > . ~/.bash_aliases > > My .bash_aliases was a simple test: > > alias rt="echo the rt alias worked" > echo the alias file was run > > > When I source directly with > > . ~/.bash_rc > > The alias gets set, I see the message 'the alias file was run' and the > rt command works as expected. So, every bash terminal session has > access to rt. Great. Awesome. That's how it should work. > > However, I want to set aliases using Ruby. I change my .bash_rc > > from: . ~/.bash_aliases > > to: ruby ~/set_aliases.rb > > My set_aliases.rb looks like this: > > system "source ~/.bash_aliases" > > Now, each terminal session I open actually runs the file. I know this > because I get the message 'the alias file was run'. However, the > terminal session doesn't have access to the rt alias (command unknown). > > I'm thinking that the problem has to do with the process context that > the aliases are set in, but I don't know how to fix the problem. > > Any ideas would be greatly appreciated. Thanks. a shell must be interactive to obtain aliases. this will work harp:~ > cat a.rb require 'rubygems' require 'session' lines = lambda{|string| string.split %r/\n/} bash = Session::Bash::new 'program' => 'bash --login -i' stdout, stderr = bash.execute 'alias' p lines[stdout].grep(/ua/) stdout, stderr = bash.execute 'ua' p lines[stdout][0,10] harp:~ > ruby a.rb ["alias ua='uname -a'"] ["\e]0;ahoward@harp:~\aLinux harp.ngdc.noaa.gov 2.4.21-47.0.1.EL #1 Fri Oct 13 18:04:55 EDT 2006 i686 i686 i386 GNU/Linux", "\e]0;ahoward@harp:~\a\e]0;ahoward@harp:~\a\e]0;ahoward@harp:~\a"] but, as you see, interactive shells dump all sorts of crap to stdout. -a -- if you want others to be happy, practice compassion. if you want to be happy, practice compassion. -- the dalai lama