Could it be that Ruby is using a different shell than you are used to?
I think it uses /bin/sh by default (not sure).
Perhaps that is part of it. However, on this suggestion, I entered the
suggested shell (/bin/sh). However, the behavior hasn’t changed,
although the ‘history’ command works fine in this shell.
Just for reference, this is what I get when checking what this shell
is:
There is really no point in accessing the history of the shell because
what you likely want is the history of the invoking shell, i.e. the
one that started your ruby interpreter. AFAIK there is no way to access
that history. If you want to work with that you can do this at the
shell prompt.
history | ruby -e ‘…’
Your example with “pwd” worked because “pwd” is also an external program
(try it out with “type -a pwd”). But you can access PWD much easier
from inside Ruby:
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
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
that’s it.
The most shells provide build-in commands only in the interactive mode.
Some shells coIMost shells print something like “can’t find…”, some
shells also print a littl help.
example (on zsh):
$ echo history | zsh
history: not interactive shell
regards,
Matthias
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.