unexpected behavior bash, set -o vi, history -a, and HISTFILE

Login or Register for Dates, Times and to Reply

Thread Tools Search this Thread
# 1  
unexpected behavior bash, set -o vi, history -a, and HISTFILE

I am trying to get my history in sync in multiple bash sections and things aren't working the way I expect.

Desired behavior, hitting esc-K in all bash sessions (same userid and machine) will use the same history.

Observed behavior: Esc-k shows the history of the current session, rather than the latest command in the HISTFILE. I can see my last command being appended to the HISTFILE, but esc-K only scrolls through the current session's history.

Here are some of my env settings:
$ set|grep -i hist
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}"; echo -ne "\007";history -a'

Thanks for helping me figure this out.
# 2  
HISTFILE does not work that way. It is written when your interactive shell quits.
# 3  
Originally Posted by Corona688
HISTFILE does not work that way. It is written when your interactive shell quits.
Unless you issue a `history -a` after each command, which I am in my PROMPT_COMMAND.
# 4  
Here is something that might suit your needs: http://ptspts.blogspot.fr/2011/03/ho...ize-shell.html
This User Gave Thanks to jlliagre For This Post:
# 5  
Originally Posted by jlliagre
Here is something that might suit your needs:

---------- Post updated at 11:47 AM ---------- Previous update was at 11:34 AM ----------

This is a smart solution. A bit complicated, but smart. I wish that bash could do this on it's own. I am a bit weary about finding a bug down the road with the trap and re-execution of the command. Also, potential debugging of what is happening to the modified environment variables. I am sure it works, but just too much hacking going on for the sake of syncing sessions.
# 6  
This is one of the reasons I'm always using ksh when available.
# 7  
Is the behavior different in ksh?
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #779
Difficulty: Medium
Spectrum analysis is also referred to as time domain analysis or time density estimation.
True or False?

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Different behavior between bash shell and bash script for cmd

So I'm trying to pass certain json elements as env vars and use them later on in a script. Sample json: JSON='{ "Element1": "file-123456", "Element2": "Name, of, company written in, a very weird way", "Element3": "path/to/some/file.txt", }' (part of the) script: for s... (5 Replies)
Discussion started by: da1
5 Replies

2. UNIX for Advanced & Expert Users

Bash : While Loop behavior

Good Morning I think there may be something I dont understand fully. The following code works well, but I dont like the set domen method. #!/bin/bash # domen="y" while do echo " M A I N - M E N U" echo "1. Contents of /etc/passwd" echo "2. List of users currently logged" echo... (10 Replies)
Discussion started by: popeye
10 Replies

3. Shell Programming and Scripting

Unexpected Echo Behavior

Hello all, I have a basic issue that I can't seem to search for since I'm not sure how to describe the behavior. Could anyone kindly assist the novice? (Sample) File Data: bundle-ppp-1/1.78 bundle-ppp-1/2.80 bundle-ppp-1/1.79 bundle-ppp-1/2.81 bundle-ppp-1/1.80 bundle-ppp-1/2.82... (6 Replies)
Discussion started by: sjrupp
6 Replies

4. UNIX for Dummies Questions & Answers

Launchd-owned processes unexpected behavior

Ok, so I have been struggling with this for a few days and I think I need an explanation of a few things before I go any further. I'm not sure it's possible to do what I'm trying, so before I pull my hair out, here is what I'm doing: I have written a program in LiveCode that sits on our... (2 Replies)
Discussion started by: nextyoyoma
2 Replies

5. IP Networking

iptables DNAT of outgoing destination port, unexpected behavior

Not sure if this should be here or in the security section. I am developing software that dynamically manipulates netfilter/iptables rules (through system() calls of the command strings, I'm not trying to hack the netfilter code). Basically, UDP messages that are sent by an application on, say,... (0 Replies)
Discussion started by: cjh19460
0 Replies

6. Solaris

Unexpected df behavior

Hi, I have Sun SPARC Enterprise T5140 with two 2,5" 15rpm 146GB SAS HDD. In friday there were a lot of errors with fs on them. After reconfiguring all seemed to be fine but today I get the following strange behavior of df -kh command and troubles with files, I written on first disk in friday.... (9 Replies)
Discussion started by: Sapfeer
9 Replies

7. Shell Programming and Scripting

BASH quoting behavior

The block below isn't a surprise:$ ls file1 file2 file3 $ x=* $ echo $x file1 file2 file3 $ echo '$x' $x $ echo "$x" * $But I found this block a bit bewildering:$ echo $x' >' * $I'm wondering why substitution wasn't performed on the $x, since it was unquoted (as far as I can tell).... (5 Replies)
Discussion started by: na5m
5 Replies

8. Solaris

How to set history key in Solaris

Hi Solaris guys, I just have my solaris 10 setup on x86 old box... How can i get history key? eg. Linux using up/down arrow key to call history command... HPUX using Esc-k How can i do the samething in Solaris? Thanks in advanced! Regards, gary (3 Replies)
Discussion started by: timontt
3 Replies

9. Shell Programming and Scripting

Mimic bash history behavior

Does anyone know of a way to mimic the up arrow/down arrow type bash behavior within a shell script? Say I have a scripted menu, and would like to be able to up arrow to bring up the last X number of lines of user input? Thanks to anybody with a suggestion. :) (0 Replies)
Discussion started by: sysera
0 Replies

Featured Tech Videos