From: Ken Bloom Date: 2006-08-11T23:30:06+09:00 Subject: Re: access built-in shell commands like 'history' or 'fc' On Wed, 09 Aug 2006 12:28:44 -0700, bwv549 wrote: > How do I access built-in shell commands (like 'history' or 'fc') with a > system call? > > Not what I was expecting: > % ruby -e 'puts `history`' > -e:1: command not found: history > > But this works fine: > > % ruby -e 'puts `pwd`' > /home/john > > I've tried this: > > % ruby -e 'system "history >tmp.tmp"; puts IO.read("tmp.tmp")' > > And no errors are generated, but there is nothing in tmp.tmp, either. > > Thanks I think under certain circumstances either ruby doesn't call the shell (and just calls the executable) or the shell doesn't recognize builtin commands when called as sh -c For example: irb(main):001:0> puts `cd scratch` (irb):1: command not found: cd scratch => nil irb(main):002:0> puts `pwd` /home/bloom => nil irb(main):003:0> puts `type pwd` (irb):3: command not found: type pwd => nil irb(main):004:0> puts `type pwd && echo` pwd is a shell builtin => nil irb(main):005:0> puts `which pwd` /bin/pwd => nil pwd works because it also happens to be a binary in /bin --Ken Bloom -- Ken Bloom. PhD candidate. Linguistic Cognition Laboratory. Department of Computer Science. Illinois Institute of Technology. http://www.iit.edu/~kbloom1/