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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
#! /bin/sh
# This is a test script for the Katepart Bash Syntax Highlighting by
# Wilbert Berendsen. This is not runnable !!!
# The highlighting recognizes basic types of input, and has a few special cases that
# are all in FindCommands. The main objective is to create really proper nesting of
# (multiline) strings, variables, expressions, etc.
# ============== Tests: ===============
# basic types:
echo 'single quoted string'
echo "double quoted string"
echo $'string with esc\apes\x0din it'
echo $"string meant to be translated"
# comments:
# this is a comment
#this too
echo this is#nt a comment
dcop kate EditInterface#1 #this is
# brace expansion
mv my_file.{JPG,jpg}
# special characters are escaped:
echo \(output\) \&\| \> \< \" \' \*
# variable substitution:
echo $filename.ext
echo $filename_ext
echo ${filename}_ext
echo text${array[$subscript]}.text
echo text${array["string"]}.text
echo ${!prefix*}
echo ${!redir}
echo short are $_, $$, $?, ${@}, etc.
echo ${variable/a/d}
echo ${1:-default}
# expression subst:
echo $(( cd << ed + 1 ))
# command subst:
echo $(ls -l)
echo `cat myfile`
# file subst:
echo $(<$filename)
echo $(</path/to/myfile)
# process subst:
sort <(show_labels) | sed 's/a/bg' > my_file.txt 2>&1
# All substitutions also work in strings:
echo "subst ${in}side string" 'not $inside this ofcourse'
echo "The result is $(( $a + $b )). Thanks!"
echo "Your homedir contains `ls $HOME |wc -l` files."
# Escapes in strings:
p="String \` with \$ escapes \" ";
# keywords are black, builtins dark purple and common commands lighter purple
set
exit
login
# Other colorings:
error() {
cat /usr/bin/lesspipe.sh
runscript >& redir.bak
exec 3>&4
}
# do - done make code blocks
while [ $p -lt $q ]
do
chown 0644 $file.$p
done
# braces as well
run_prog | sort -u |
{
echo Header
while read a b d
do
echo $a/$b/$c
done
echo Footer
}
# Any constructions can be nested:
echo "A long string with $(
if [ $count -gt 100 ] ; then
echo "much"
else
echo "not much"
fi ) substitutions." ;
# Even the case construct is correctly folded:
test -f blaat &&
( do_something
case $p in
*bak)
do_bak $p
;;
*)
dont_bak $p
;;
esac
) # despite the extra parentheses in the case construction.
# variable assignments:
DIR=/dev
p=`ls`
LC_ALL="nl" dcop 'kate*'
_VAR=val
ARR=(this is an array)
ARR2=([this]=too [and]="this too")
usage="$0 -- version $VERSION
Multiple lines of output
can be possible."
ANSWER=yes # here 'yes' isn't highlighed as command
# Some commands expect variable names, these are colored correctly:
export PATH=/my/bin:$PATH BLAAT
export A B D
local p=3 x y='\'
read x y z <<< $hallo
unset B
declare -a VAR1 VAR2 && exit
declare less a && b
# options are recoqnized:
zip -f=file.zip
./configure --destdir=/usr
make destdir=/usr/
# [[ and [ correctly need spaces to be regarded as structure,
# otherwise they are patterns (currently treated as normal text)
if [ "$p" == "" ] ; then
ls /usr/bin/[a-z]*
elif [[ $p == 0 ]] ; then
ls /usr/share/$p
fi
# Fixed:
ls a[ab]* # dont try to interprete as assignment with subscript (fixed)
a[ab]
a[ab]=sa
# Here documents are difficult to catch:
cat > myfile << __EOF__
You're right, this is definitely no bash code
But ls more $parameters should be expanded.
__EOF__
# quoted:
cat << "EOF" | egrep "this" >&4 # the rest of the line is still considered bash source
You're right, this is definitely no bash code
But ls more $parameters should be expanded. :->
EOF
# indented:
if true
then
cat <<- EOF
Indented text with a $dollar or \$two
EOF
elif [ -d $file ]; then
cat <<- "EOF"
Indented text without a $dollar
EOF
fi
|