Line | |
---|
1 | LC_ALL=C
|
---|
2 | LANG=C
|
---|
3 | trap 'rm /tmp/newhistory' 0
|
---|
4 |
|
---|
5 | file=bax
|
---|
6 | histchars='!^#' # make sure history comment char is set correctly
|
---|
7 |
|
---|
8 | unset HISTFILESIZE
|
---|
9 |
|
---|
10 | history -c
|
---|
11 |
|
---|
12 | HISTFILE=history.list
|
---|
13 | HISTCONTROL=ignoreboth
|
---|
14 | HISTIGNORE='&:#*:history*:fc*'
|
---|
15 | # we will end up exercising the history stifling code as a result
|
---|
16 | HISTSIZE=32
|
---|
17 |
|
---|
18 | shopt -s cmdhist
|
---|
19 | set -o history
|
---|
20 |
|
---|
21 | history -p '!!'
|
---|
22 |
|
---|
23 | # this should result in a failed history expansion error
|
---|
24 | history -p '!!:z'
|
---|
25 |
|
---|
26 | history
|
---|
27 |
|
---|
28 | HISTFILE=/tmp/newhistory
|
---|
29 | history -a
|
---|
30 |
|
---|
31 | history -w
|
---|
32 |
|
---|
33 | history -s "echo line 2 for history"
|
---|
34 | history
|
---|
35 | history -p '!e'
|
---|
36 | history -p '!!'
|
---|
37 |
|
---|
38 | set -H
|
---|
39 | !!
|
---|
40 | !e
|
---|
41 |
|
---|
42 | history
|
---|
43 |
|
---|
44 | echo a b c d e
|
---|
45 | !?ch?
|
---|
46 | !-2
|
---|
47 | ^2^8
|
---|
48 |
|
---|
49 | !2
|
---|
50 |
|
---|
51 | # we're selecting /bin/sh -c ...; we want `sh'
|
---|
52 | echo !-1:0:t
|
---|
53 | # we're selecting /bin/sh -c ...; we want `/bin'
|
---|
54 | echo !-2:0:h
|
---|
55 | # we're selecting `echo a b c d e'; we want `e'
|
---|
56 | echo !?d?:5
|
---|
57 |
|
---|
58 | echo a b c d e
|
---|
59 | echo !-1:2-$
|
---|
60 | echo !-2:2-4
|
---|
61 | echo !-2:3*
|
---|
62 | echo !!:*
|
---|
63 |
|
---|
64 | echo !?a?:2-
|
---|
65 |
|
---|
66 | echo file.c
|
---|
67 | echo !!:$:r
|
---|
68 | echo !-2:$:e
|
---|
69 | echo !-3:$:r:q
|
---|
70 |
|
---|
71 | echo $file.c
|
---|
72 | echo !!:$:r
|
---|
73 | echo !-2:^:e
|
---|
74 | echo !-3:$:r:q
|
---|
75 |
|
---|
76 | echo a b c d e
|
---|
77 | echo !!:1-$:x
|
---|
78 | echo !-2:1-$:q
|
---|
79 |
|
---|
80 | echo foo.c foo.o foo.html foo.h
|
---|
81 | !!:s/foo/bar/
|
---|
82 | !-2:gs/foo/bar/
|
---|
83 | !!:gs/bar/x&/
|
---|
84 | !-2:g&
|
---|
85 |
|
---|
86 | # make sure we can use any delimiter in the substitution, not just `/'
|
---|
87 | !!:gs+bar+whix+
|
---|
88 |
|
---|
89 | !!:p
|
---|
90 |
|
---|
91 | # wow
|
---|
92 | echo !?.o?:%:r:q
|
---|
93 |
|
---|
94 | !!:0 !?.h?:%:q
|
---|
95 | !!:-$
|
---|
96 | !:-$
|
---|
97 |
|
---|
98 | history
|
---|
99 |
|
---|
100 | # make sure single quotes inhibit history expansion
|
---|
101 | echo '!!'
|
---|
102 |
|
---|
103 | # make sure backslashes can quote the history expansion character
|
---|
104 | echo \!\!
|
---|
105 |
|
---|
106 | # but other expansions on the line should still be processed
|
---|
107 |
|
---|
108 | echo '!!' !!:*
|
---|
109 | history -c
|
---|
110 | unset HISTFILE
|
---|
111 |
|
---|
112 | # make sure that the special bash cases are not history expanded
|
---|
113 | case p in
|
---|
114 | [!A-Z]) echo ok 1;;
|
---|
115 | esac
|
---|
116 |
|
---|
117 | var1='ok 2'
|
---|
118 | var2=var1
|
---|
119 |
|
---|
120 | echo ${!var2}
|
---|
121 |
|
---|
122 | # Bash-2.01[.1] fails this test -- it attempts history expansion after the
|
---|
123 | # history_expansion_char
|
---|
124 | echo ok 3 # !1200
|
---|
Note:
See
TracBrowser
for help on using the repository browser.