Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm sometimes logged in on a host which I do not control and where PROMPT_COMMAND is readonly. Is there some way to work around this to run history commands anyway, for example using PS1? I've tried PS1='$(history -a; history -c; history -r; echo finished)' - It prints finished at each prompt, but it doesn't seem to work:

  1. Open two terminals A and B on the same host.
  2. In terminal A, run a command a.
  3. In terminal B, run a command b.
  4. It terminal B, press twice.

On a host where PROMPT_COMMAND='history -a; history -c; history -r;', this will result in terminal B showing a. On a host where PS1 starts with $(history -a; history -c; history -r; echo finished) it will instead show whichever command was run before both terminals were opened. The obvious reason is that the command in PS1 is run in a subshell.

Another alternative is to bypass the global RC-file altogether:

bash --rcfile ~/.bashrc

However, circumventing the use of the standard value of PROMPT_COMMAND will very likely not be accepted by the sysadmin for policy reasons.

share|improve this question
2  
You can work around a readonly var by spawning a new shell, with an alternate rc file. –  jordanm Aug 23 '12 at 15:17
1  
@jw013 I have lots of command substitutions in PS1 which work, but this one has to update the state of the parent shell, which is probably not possible. –  l0b0 Aug 23 '12 at 15:25
1  
@jw013 Presumably the PROMPT_COMMAND is doing some kind of logging by policy. @l0b0 Would the admins object to your using zsh if you supplied a precmd that's similar to their PROMPT_COMMAND? –  Gilles Aug 23 '12 at 20:42
1  
Please. I'd rather discuss the technical issue. –  l0b0 Aug 24 '12 at 2:06
2  
@l0b0 The technical issue has been solved - get a non-readonly PROMPT_COMMAND by running a new shell. Ignoring real-life when making technical decisions is a recipe for outrageous setups. Sounds like you have much deeper non-technical problems if you can't even run a new shell. –  jw013 Aug 24 '12 at 13:57
show 6 more comments

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.