Shopt -s histappend


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Shopt -s histappend
# 1  
Old 07-20-2019
Shopt -s histappend

What is the point of this? Whenever I close my shell it appends to the history file without adding this. I have never seen it overwrite my history file.

Code:
# When the shell exits, append to the history file instead of overwriting it
shopt -s histappend

# 2  
Old 07-21-2019
I am not 100% sure, but I "think" it is there for some legacy backward compatibility issue.

On my systems, the history is always appended even when histappend is set to off.

For example, on macOS:

Code:
Tim$ shopt
cdable_vars    	off
cdspell        	off
checkhash      	off
checkwinsize   	on
cmdhist        	on
compat31       	off
dotglob        	off
execfail       	off
expand_aliases 	on
extdebug       	off
extglob        	off
extquote       	on
failglob       	off
force_fignore  	on
gnu_errfmt     	off
histappend     	off
histreedit     	off
histverify     	off
hostcomplete   	on
huponexit      	off
interactive_comments	on
lithist        	off
login_shell    	on
mailwarn       	off
no_empty_cmd_completion	off
nocaseglob     	off
nocasematch    	off
nullglob       	off
progcomp       	on
promptvars     	on
restricted_shell	off
shift_verbose  	off
sourcepath     	on
xpg_echo       	off

Linux:

Code:
# shopt
autocd         	off
cdable_vars    	off
cdspell        	off
checkhash      	off
checkjobs      	off
checkwinsize   	on
cmdhist        	on
compat31       	off
compat32       	off
compat40       	off
compat41       	off
compat42       	off
compat43       	off
complete_fullquote	on
direxpand      	off
dirspell       	off
dotglob        	off
execfail       	off
expand_aliases 	on
extdebug       	off
extglob        	on
extquote       	on
failglob       	off
force_fignore  	on
globasciiranges	off
globstar       	off
gnu_errfmt     	off
histappend     	off
histreedit     	off
histverify     	off
hostcomplete   	off
huponexit      	off
inherit_errexit	off
interactive_comments	on
lastpipe       	off
lithist        	off
login_shell    	on
mailwarn       	off
no_empty_cmd_completion	off
nocaseglob     	off
nocasematch    	off
nullglob       	off
progcomp       	on
promptvars     	on
restricted_shell	off
shift_verbose  	off
sourcepath     	on
xpg_echo       	off

In both example cases above, the history is appended and not overwritten even though it is shown to be "off".
# 3  
Old 07-21-2019
Supplementary info, from a bash-related man page:

Quote:
histappend
If set, the history list is appended to the history file when the shell exits,
rather than overwriting the history file.

shopt -s histappend

To append every line to history individually set:
PROMPT_COMMAND='history -a'

With these two settings, a new shell will get the history lines from all previous
shells instead of the default 'last window closed'>history
(the history file is named by the value of the HISTFILE variable)
See also:

FWIW:

Code:
mysql> select manid, token,strlen from  neo_man_page_entry where token like '%shopt';
+--------+----------------+--------+
| manid  | token          | strlen |
+--------+----------------+--------+
|  14767 | redhat_1_shopt |  69032 |
| 127977 | centos_1_shopt |  89209 |
+--------+----------------+--------+
2 rows in set (0.57 sec)

More broadly, FYI only:

Code:
mysql> select manid, token,strlen from  neo_man_page_entry where formatted like '% shopt %';
+--------+------------------------+--------+
| manid  | token                  | strlen |
+--------+------------------------+--------+
|   1973 | centos_1_exit          |  89209 |
|   4219 | redhat_1_times         |  69032 |
|   5061 | centos_1_pushd         |  89209 |
|   7679 | opensolaris_1_bash     | 254197 |
|   8146 | centos_7_glob          |   7955 |
|   8572 | mojave_1_bash          | 253714 |
|   8849 | redhat_1_alias         |  69032 |
|   8991 | redhat_1_bash          | 232097 |
|   9018 | redhat_1_bg            |  69032 |
|   9023 | redhat_1_bind          |  69032 |
|   9052 | redhat_1_break         |  69032 |
|   9079 | redhat_1_builtin       |  69032 |
|   9080 | redhat_1_builtins      |  69032 |
|   9169 | redhat_1_cd            |  69032 |
|   9329 | redhat_1_command       |  69032 |
|   9335 | redhat_1_compgen       |  69032 |
|   9348 | redhat_1_complete      |  69032 |
|   9374 | redhat_1_continue      |  69032 |
|   9578 | redhat_1_declare       |  69032 |
|   9655 | redhat_1_dirs          |  69032 |
|   9668 | redhat_1_disown        |  69032 |
|   9893 | redhat_1_enable        |  69032 |
|  10022 | redhat_1_eval          |  69032 |
|  10036 | redhat_1_exec          |  69032 |
|  10037 | redhat_1_exit          |  69032 |
|  10052 | redhat_1_export        |  69032 |
|  10121 | redhat_1_fc            |  69032 |
|  10130 | redhat_1_fg            |  69032 |
|  10420 | redhat_1_getopts       |  69032 |
|  10786 | redhat_1_hash          |  69032 |
|  10812 | redhat_1_help          |  69032 |
|  10833 | redhat_1_history       |  69032 |
|  11127 | linux_1_bash           | 288326 |
|  11339 | redhat_1_let           |  69032 |
|  11414 | redhat_1_local         |  69032 |
|  11437 | redhat_1_logout        |  69032 |
|  11742 | mojave_1_sh            | 253714 |
|  13778 | redhat_1_popd          |  69032 |
|  14171 | redhat_1_pushd         |  69032 |
|  14345 | redhat_1_read          |  69032 |
|  14352 | redhat_1_readonly      |  69032 |
|  14401 | redhat_1_return        |  69032 |
|  14666 | redhat_1_set           |  69032 |
|  14745 | redhat_1_sh            | 232097 |
|  14765 | redhat_1_shift         |  69032 |
|  14767 | redhat_1_shopt         |  69032 |
|  14956 | redhat_1_source        |  69032 |
|  15437 | redhat_1_trap          |  69032 |
|  15479 | redhat_1_type          |  69032 |
|  15488 | redhat_1_typeset       |  69032 |
|  15507 | redhat_1_ulimit        |  69032 |
|  15508 | redhat_1_unalias       |  69032 |
|  15509 | redhat_1_umask         |  69032 |
|  15561 | redhat_1_unset         |  69032 |
|  15748 | redhat_1_wait          |  69032 |
|  27226 | centos_1_enable        |  89209 |
|  30899 | centos_1_local         |  89209 |
|  31042 | centos_1_type          |  89209 |
|  32972 | centos_1_hash          |  89209 |
|  33250 | centos_1_read          |  89209 |
|  56727 | linux_7_builtins       |  89018 |
|  56728 | linux_7_bash-builtins  |  89018 |
|  57787 | redhat_1_jobs          |  69032 |
|  57957 | redhat_1_suspend       |  69032 |
|  63212 | centos_1_sh            | 287877 |
|  68185 | debian_1_bash          | 288613 |
|  68186 | debian_1_bash-static   | 288613 |
| 116150 | debian_7_bash-builtins |  89296 |
| 116293 | debian_7_glob          |   7955 |
| 122870 | centos_1_builtins      |  89209 |
| 125392 | centos_1_alias         |  89209 |
| 125457 | centos_1_bash          | 287877 |
| 125471 | centos_1_bg            |  89209 |
| 125473 | centos_1_bind          |  89209 |
| 125490 | centos_1_break         |  89209 |
| 125498 | centos_1_builtin       |  89209 |
| 125522 | centos_1_caller        |  89209 |
| 125542 | centos_1_cd            |  89209 |
| 125613 | centos_1_command       |  89209 |
| 125615 | centos_1_compgen       |  89209 |
| 125617 | centos_1_complete      |  89209 |
| 125618 | centos_1_compopt       |  89209 |
| 125626 | centos_1_continue      |  89209 |
| 125709 | centos_1_declare       |  89209 |
| 125739 | centos_1_dirs          |  89209 |
| 125741 | centos_1_disown        |  89209 |
| 125870 | centos_1_eval          |  89209 |
| 125874 | centos_1_exec          |  89209 |
| 125879 | centos_1_export        |  89209 |
| 125906 | centos_1_fc            |  89209 |
| 125920 | centos_1_fg            |  89209 |
| 126051 | centos_1_getopts       |  89209 |
| 126382 | centos_1_help          |  89209 |
| 126388 | centos_1_history       |  89209 |
| 126595 | centos_1_jobs          |  89209 |
| 126701 | centos_1_let           |  89209 |
| 126745 | centos_1_logout        |  89209 |
| 126817 | centos_1_mapfile       |  89209 |
| 127604 | centos_1_popd          |  89209 |
| 127761 | centos_1_readonly      |  89209 |
| 127806 | centos_1_return        |  89209 |
| 127934 | centos_1_set           |  89209 |
| 127977 | centos_1_shopt         |  89209 |
| 127978 | centos_1_shift         |  89209 |
| 128052 | centos_1_source        |  89209 |
| 128113 | centos_1_suspend       |  89209 |
| 128221 | centos_1_times         |  89209 |
| 128273 | centos_1_trap          |  89209 |
| 128290 | centos_1_typeset       |  89209 |
| 128298 | centos_1_ulimit        |  89209 |
| 128300 | centos_1_umask         |  89209 |
| 128301 | centos_1_unalias       |  89209 |
| 128319 | centos_1_unset         |  89209 |
| 128414 | centos_1_wait          |  89209 |
| 139476 | suse_1_bashbuiltins    |  98283 |
| 151669 | suse_1_bash            | 280501 |
| 156941 | opendarwin_1_bash      | 231854 |
| 179879 | suse_8_crm_shadow      |  47178 |
| 193041 | sunos_1_bash           | 248122 |
| 193250 | osx_1_bash             | 253660 |
| 194941 | osx_1_sh               | 253660 |
| 237536 | plan9_1_bash           | 334359 |
| 249650 | debian_7_builtins      | 107408 |
| 250630 | xfree86_1_bash         | 334401 |
| 253484 | x11r4_1_bash           | 334359 |
| 260350 | freebsd_1_bash         | 317993 |
| 260730 | hpux_1_bash            | 317930 |
| 266705 | v7_1_bash              | 317888 |
| 270072 | minix_1_bash           | 317951 |
| 270584 | posix_1_bash           | 317951 |
| 273989 | php_1_bash             | 317909 |
| 275518 | bsd_1_bash             | 317909 |
+--------+------------------------+--------+
132 rows in set (12.78 sec)

These 2 Users Gave Thanks to Neo For This Post:
# 4  
Old 07-23-2019
So adding
Code:
shopt -s histappend
PROMPT_COMMAND='history -a'

in your .bashrc will mimic the behaviour of ksh in that it writes all commands to its history file as (after?) it executes them.

Presumably the correct order of history -a and history -n would allow two or more shells to share their history, exactly like ksh (my least favourite feature of ksh)

Andrew
Login or Register to Ask a Question

Previous Thread | Next Thread

2 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash 'shopt' doubt

Hi, I am using bash shell's extended pattern matching. What tweak the following code needs in order to get the expected output? shopt -s extglob f="a@b@_c@d@_e" echo "${f/@(@|@_)/__}" My expected output is: a__b__c__d__e but the actual output is: a__b@_c@d@_e # that is, how to... (3 Replies)
Discussion started by: royalibrahim
3 Replies

2. Shell Programming and Scripting

shopt -s nullglob

Hi, I am using BASH. In a directory there are files that match either of the following 2 patterns: *.L1A_AC* or S*.L1A_MLAC* I would like to write a script that will include a for loop, where for each file in the directory, a certain function will be performed. For example: for FILE in... (4 Replies)
Discussion started by: msb65
4 Replies
Login or Register to Ask a Question