Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to run for example history -w for underlying bash shell from ruby script?
Or better is it possible to run builtin command for bash shell knowing only its pid?

The only way I found is to trap signal like trap "history -w" SIGUSR1 and then send signal to process, but I am not sure that it is a good practice and USR1 is not used by bash, also this way I can execute max 2 commands (USR1 and USR2). And I have to define trap before using it.

I am on Mac so there is not SIGRTMIN..SIGRTMAX.

Why I need this:

I created ruby shell script dt which opens new tab next to current with same working dir, then I wrote that can do same thing but can do this even if tab is busy running something (I call it using Spark). But it will be much better if history will be also same in duplicated tab and for dt I can just use alias dt='history -w; dt', but how can I do this from

share|improve this question
@Daniel: I clarified why I need this – tig Dec 22 '10 at 9:22

There's no off-the-shelf way to cause a shell to execute a command, other than typing in on its standard input. The easiest thing would be to have bash check some file, or run history -w, as part of PROMPT_COMMAND (a command that is executed before each prompt).

I think what you're after is in fact Real-time history export amongst Bash terminal windows, and perhaps Better bash history.

You might also consider using zsh (available in most Linux/OSX/other unix package repositories) and its inc_append_history and share_history options.

share|improve this answer
zsh is maybe good, but it can't handle utf-8 input and this stops me right away (though I know it can print those chars) – tig Dec 23 '10 at 5:10
@tig: UTF-8 is supported in zsh 4.3 (which in spite of being labeled “development” is definitely “reasonably stable”: it doesn't crash or anything, and new minor releases aren't even in the habit of having incompatible changes). – Gilles Dec 23 '10 at 8:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.