LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-06-2016, 03:33 PM   #16
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled

Quote:
Originally Posted by dedec0 View Post
The configuration means that, but it does not work in cases with parallel sessions.
Oh, "that". Yes, I live in terminals (SysAdmin) and history being "in sync" never worked for me.
 
Old 09-06-2016, 08:36 PM   #17
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS,Manjaro
Posts: 5,678

Rep: Reputation: 2712Reputation: 2712Reputation: 2712Reputation: 2712Reputation: 2712Reputation: 2712Reputation: 2712Reputation: 2712Reputation: 2712Reputation: 2712Reputation: 2712
So, if that is indeed the case the BASH developers may decide NEVER to solve the problem, because it is not in fact any kind of bug.
What the OP may require then, is some kind of process that removes the dups as the last parallel session closes and the history file is closed and inactive.
 
Old 09-07-2016, 01:33 PM   #18
dedec0
Senior Member
 
Registered: May 2007
Posts: 1,372

Original Poster
Rep: Reputation: 51
Post Steps to make history duplicates, when it should not have

I am using Gnome 2's gnome-terminal, this gives me easy open/close/change in terminal sessions: ctrl+shift+t open a new terminal; "[ctrl+c] ctrl+d" closes it; alt+[N] changes to other sessions, keeping the current one open.

The relevant parts of my .bashrc, .bash_login and .bash_logout are:

.bashrc:
Code:
# many parts removed, this MAY not work as is for the missing parts => point it

# I am not sure what this line do, but it is there:
# If not running interactively, don't do anything
[ -z "$PS1" ] && return

export HISTCONTROL=ignoreboth:erasedups
export HISTSIZE=10000
export HISTFILESIZE=10000

# append to the history file, don't overwrite it
shopt -s histappend

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

# Apaga linhas do histórico, aceitando mais de um argumento de uma vez
function histd()
{
    if (( $# < 1)); then
	echo 'Use assim: histd 15 14 13 12 [...]'
	echo -e "\tcom os números em ordem DECRESCENTE - ou não funciona"
	return
    fi
    ult=$1
    echo "history -d $1"
    teste=!$1
    echo "'$teste' devia funcionar... sqn"
    history -d $1
    while ((1)); do
	shift
	if (( $# == 0 )); then
	    break;
	fi
	if (( $ult < $1 )); then
	    echo 'Sou bonzinho, mas me ajude. Desse jeito dá errado!!'
	    echo 'Use assim: histd 15 14 13 12'
	    echo -e "\t Com TODOS os números em ordem DECRESCENTE!"
	    return
	fi
	echo "history -d $1"
	ult=$1
	history -d $1
    done;
}

# rmhist <primeira-linha-apagada> <última-apagada>
# -> Line numbers according to the output of history.
# -> Use history -w to force a write to the history file.
function rmhist()
{
    if (( $# < 1)); then
	echo 'rmhist <1a-linha-apagada> <última-linha-apagada>'
	echo -e '\tOu...'
	echo 'rmhist <quant-de-últimas-linhas-apagadas>'
	return
    fi

    if (( $# == 1 )); then
	comeco=$(( $HISTCMD-1 ))
	if (( $1 > 10 )); then return; fi
	if (( $1 < 0 )); then return; fi
	fim=$(( $HISTCMD-$1 ))
	for (( i=$comeco; i>=$fim; i--)); do
	    echo -n $i,
	    history -d $i
	done;
	echo
    elif (( $# == 2)); then
	for (( i=$2-$1; i>=0; i--)); do
	    history -d $1
	done
    fi
}
# vim: fileencoding=utf-8
.bash_logout (all of it)
Code:
# ~/.bash_logout: executed by bash(1) when login shell exits.

# when leaving the console clear the screen to increase privacy

if [ "$SHLVL" = 1 ]; then
    [ -x /usr/bin/clear_console ] && /usr/bin/clear_console -q
fi
.bash_login does not exist
Code:

I am doing this having some terminal sessions opened, and I will not close them to make these tests. I will make a few steps to make is safe against some corruptions, if they are wrong or are potentially not enough, please say!

I assume that you are using ignoreboth to ignore commands with spaces before them => we can type commands that will not affect the history of any session.

All comments that start with #N should be made in the session number N. #1 => in session 1 and so on. Other comments are just to show other actions, like openning and closing sessions (with a ctrl+d, not with the exit command).

Some commands are intentionally started with spaces. Steps to have duplicate lines in history:

Code:
 # make a backup, in any session, of the current history.
 cp ~/.bash_history ~/.bash_history__beforeTests.2016.09.07 #save everything as is

 # open session 1
history -c #1
history -w #1
history #1 should show only these 2 last lines

 # open session 2
 history #2 note the space. Will show only the -w line
aaaa #2
bbbb #2
cccc #2
dddd #2

 # close session 2

 # open session 3
 history #3
 # Should be:
 #   1  history -w
 #   2  aaaa
 #   3  bbbb
 #   4  cccc
 #   5  dddd

 # open session 4
bbbb #4
 history #4
 # Should be:
 #   1  history -w
 #   2  aaaa
 #   3  cccc
 #   4  dddd
 #   5  bbbb

 # close session 4
 # close session 3

 # open session 5
 history #5
 # Should be:
 #   1  history -w
 #   2  aaaa
 #   3  bbbb
 #   4  cccc
 #   5  dddd
 #   6  bbbb
 # note history entries 3 and 6: both should not exist!
 # close all these sessions

 # now, in any other session, reset the history to what it
 # was before the tests were made
 cp ~/.bash_history__beforeTests.2016.09.07 ~/.bash_history
I have not tried other tests now, but I have repeated this one (to test it worked). It may not be the only way to get duplicates inserted in the history.

Now I hope that my restored backup is still there the next time I reboot my computer.

Last edited by dedec0; 09-07-2016 at 03:08 PM.
 
Old 09-09-2016, 06:31 AM   #19
dedec0
Senior Member
 
Registered: May 2007
Posts: 1,372

Original Poster
Rep: Reputation: 51
Quote:
Originally Posted by dedec0 View Post
Now I hope that my restored backup is still there the next time I reboot my computer.
Rebooted the computer. History is there, backup and restore worked as intended.

Now I am just waiting one solution to remove older duplicates of history lines that keeps the relative sequence of all entries.

The steps to make it contain duplicates are above, and with safe steps for anyone to test it.
 
  


Reply

Tags
bash history



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Why does BASH history command have no history when run in script ? lump_of_lard Programming 4 01-30-2015 09:45 AM
Bash history samineru Linux - Software 1 07-14-2011 06:57 AM
Bash history delete command from bash itself ashishag Linux - Software 6 05-02-2010 03:39 AM
copying a lot of files with bash or terminal. rob-n Linux - Newbie 3 04-13-2004 06:01 PM
Bash History ukndoit Linux - Security 2 10-16-2003 09:02 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:02 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration