where does the discrepancy between \# in PS1 and n in !n come from?
Posted
by
Cbhihe
on Ask Ubuntu
See other posts from Ask Ubuntu
or by Cbhihe
Published on 2014-06-13T10:04:20Z
Indexed on
2014/06/13
15:42 UTC
Read the original article
Hit count: 235
Something has been gnawing at me for a while now and I can't seem to find a relevant answer either in man pages or using your 'Don't be evil' search engine.
My .bashrc has the following:
shopt -s histappend
HISTSIZE=100
HISTFILESIZE=0 # 200 previous value
Putting HISTFILESIZE to 0 allows me to start with a clean history slate with each new term window.
I find it practical in conjunction with using a prompt that contains \#
, because when visualizing a previous command before recalling it with !n
or !-p
, one can just do:
$ history | more
to see its relevant "n" value
In my case, usually the result of:
$ \history | tail -1 | awk '{print $1}' # (I know this is an overkill, don't flame me)
equals the expanded value of # in PS1 minus 1, which is how I like it to be at all times. But then, sometimes not. At times the expanded value of # sort of "runs away". It's incremented in such a a manner that it becomes > than
$(( $(\history | tail -1 | awk '{print $1}')+1 ))
Any pointers, anyone?
© Ask Ubuntu or respective owner