1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
|
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
LC_ALL=C
LANG=C
trap 'rm $TMPDIR/newhistory' 0
file=bax
histchars='!^#' # make sure history comment char is set correctly
unset HISTFILESIZE HISTTIMEFORMAT
history -c
HISTFILE=history.list
HISTCONTROL=ignoreboth
HISTIGNORE='&:#*:history*:fc*'
# we will end up exercising the history stifling code as a result
HISTSIZE=32
shopt -s cmdhist
set -o history
history -p '!!'
# this should result in a failed history expansion error
history -p '!!:z'
history
HISTFILE=$TMPDIR/newhistory
history -a
history -w
history -s "echo line 2 for history"
history
history -p '!e'
history -p '!!'
set -H
!!
!e
history
echo a b c d e
!?ch?
!-2
^2^8
!2
# we're selecting /bin/sh -c ...; we want `sh'
echo !-1:0:t
# we're selecting /bin/sh -c ...; we want `/bin'
echo !-2:0:h
# we're selecting `echo a b c d e'; we want `e'
echo !?d?:5
echo a b c d e
echo !-1:2-$
echo !-2:2-4
echo !-2:3*
echo !!:*
echo !?a?:2-
echo file.c
echo !!:$:r
echo !-2:$:e
echo !-3:$:r:q
echo $file.c
echo !!:$:r
echo !-2:^:e
echo !-3:$:r:q
echo a b c d e
echo !!:1-$:x
echo !-2:1-$:q
echo foo.c foo.o foo.html foo.h
!!:s/foo/bar/
!-2:gs/foo/bar/
!!:gs/bar/x&/
!-2:g&
# make sure we can use any delimiter in the substitution, not just `/'
!!:gs+bar+whix+
!!:p
# wow
echo !?.o?:%:r:q
!!:0 !?.h?:%:q
!!:-$
!:-$
history
# make sure single quotes inhibit history expansion
echo '!!'
# make sure backslashes can quote the history expansion character
echo \!\!
# but other expansions on the line should still be processed
echo '!!' !!:*
history -c
unset HISTFILE
# make sure that the special bash cases are not history expanded
case p in
[!A-Z]) echo ok 1;;
esac
var1='ok 2'
var2=var1
echo ${!var2}
# Bash-2.01[.1] fails this test -- it attempts history expansion after the
# history_comment_char
echo ok 3 # !1200
# bash versions through bash-4.3 fail this; they make the digit preceding the
# > into a separate word, changing the meaning of the redirection
shopt a b c d 2>/dev/null
echo !shopt-1
echo !shopt*
# make sure a :p modifier anywhere on the line affects all history expansions
echo one two three four
echo !:2:p ; echo !$
echo one two three four
echo !$ ; echo !:2:p
# problem through bash-5.2 with history word tokenization
echo $((1+2))
echo !!:1
${THIS_SH} ./histexp1.sub
${THIS_SH} ./histexp2.sub
${THIS_SH} ./histexp3.sub
${THIS_SH} ./histexp4.sub
${THIS_SH} ./histexp5.sub
${THIS_SH} ./histexp6.sub
${THIS_SH} ./histexp7.sub
|