Warning, file /frameworks/syntax-highlighting/autotests/input/highlight.sh was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 #! /bin/sh
0002 # This is a test script for the Katepart Bash Syntax Highlighting by
0003 #       Wilbert Berendsen.  This is not runnable !!!
0004 
0005 
0006 # The highlighting recognizes basic types of input, and has a few special cases that
0007 # are all in FindCommands.  The main objective is to create really proper nesting of
0008 # (multiline) strings, variables, expressions, etc.
0009 
0010 
0011 
0012 # ============== Tests: ===============
0013 
0014 # basic types:
0015 echo 'single quoted string'
0016 echo "double quoted string"
0017 echo $'string with esc\apes\x0din it'
0018 echo $"string meant to be translated"
0019 echo "$"
0020 
0021 
0022 # comments:
0023 # this is a comment
0024 #this too
0025 echo this is#nt a comment
0026 dcop kate EditInterface#1 #this is
0027 grep -e "^default/linux/amd64/" |\ #this is not a comment but #this is
0028 mkdir this\ isnt\ #a\ comment
0029 mkdir this\ isnt\\\;#a\ comment
0030 mkdir this\\ #is a comment
0031 
0032 <<'#BLOCK-COMMENT'
0033 NOTE This is the "miltiline" comment.
0034 
0035 [===[.rst:
0036 
0037 Docs
0038 ----
0039 
0040 Documentation block in ``RST`` format **starts** *here*.
0041 
0042 ]===]
0043 #BLOCK-COMMENT
0044 
0045 : << '#SC2188'
0046 [====[.rst:
0047 The *multiline* comment does not trigger the SC2188_ warning of `shellcheck`.
0048 
0049 .. _SC2188: https://www.shellcheck.net/wiki/SC2188
0050 ]====]
0051 
0052 ... continue with _normal_ Bash comment.
0053 #SC2188
0054 
0055 # brace expansion
0056 mv my_file.{JPG,jpg}
0057 echo f.{01..100..3} f.{Z..a..-3}
0058 echo f.{01..100} f.{a..Z}
0059 # no brace expansion
0060 echo f.{..100} f.{1..Z} f.{a..Z..}
0061 
0062 
0063 # special characters are escaped:
0064 echo \(output\) \&\| \> \< \" \' \*
0065 
0066 
0067 # variable substitution:
0068 echo $filename.ext
0069 echo $filename_ext
0070 echo ${filename}_ext
0071 echo text${array[$subscript]}.text
0072 echo text${array["string"]}.text
0073 echo ${!prefix*}
0074 echo ${!redir} ${!3} ${!#} ${!##} ${!@###}
0075 echo short are $_, $$, $?, ${@}, etc.
0076 echo ${variable/a/d}
0077 echo ${1:-default}
0078 echo ${10} $10a # 9 is max
0079 
0080 
0081 # expression subst:
0082 echo $(( cd << ed + 1 ))
0083 
0084 
0085 # command subst:
0086 echo $(ls -l)
0087 echo `cat myfile`
0088 
0089 
0090 # file subst:
0091 echo $(<$filename)
0092 echo $(</path/to/myfile)
0093 
0094 # process subst:
0095 sort <(show_labels) | sed 's/a/bg' > my_file.txt 2>&1
0096 
0097 
0098 # All substitutions also work in strings:
0099 echo "subst ${in}side string"  'not $inside this ofcourse'
0100 echo "The result is $(( $a + $b )). Thanks!"
0101 echo "Your homedir contains `ls $HOME |wc -l` files."
0102 
0103 
0104 # Escapes in strings:
0105 p="String \` with \$ escapes \" ";
0106 
0107 
0108 # keywords are black, builtins dark purple and common commands lighter purple
0109 set
0110 exit
0111 login
0112 
0113 
0114 # Other colorings:
0115 error() {
0116         cat /usr/bin/lesspipe.sh
0117         runscript >& redir.bak
0118         exec 3>&4
0119 }
0120 
0121 
0122 # do - done make code blocks
0123 while [ $p -lt $q ]
0124 do
0125         chown 0644 $file.$p
0126 done
0127 
0128 
0129 # braces as well
0130 run_prog | sort -u |
0131 {
0132         echo Header
0133         while read a b d
0134         do
0135                 echo $a/$b/$c
0136         done
0137         echo Footer
0138 }
0139 
0140 
0141 # Any constructions can be nested:
0142 echo "A long string with $(
0143         if [ $count -gt 100 ] ; then
0144                 echo "much"
0145         else
0146                 echo "not much"
0147         fi ) substitutions." ;
0148 
0149 
0150 # Even the case construct is correctly folded:
0151 test -f blaat &&
0152 (       do_something
0153         case $p in
0154                 *bak)
0155                         do_bak $p
0156                         ;;
0157                 *)
0158                         dont_bak $p
0159                         ;;
0160         esac
0161 ) # despite the extra parentheses in the case construction.
0162 
0163 
0164 # more control flow
0165 while :;
0166   break
0167   continue
0168   return
0169 done
0170 
0171 
0172 # variable assignments:
0173 DIR=/dev
0174 p=`ls`
0175 LC_ALL="nl" dcop 'kate*'
0176 _VAR=val
0177 ARR=(this is an array)
0178 ARR2=([this]=too [and]="this too")
0179 usage="$0 -- version $VERSION
0180 Multiple lines of output
0181 can be possible."
0182 ANSWER=yes      # here 'yes' isn't highlighed as command
0183 
0184 
0185 # Some commands expect variable names, these are colored correctly:
0186 export PATH=/my/bin:$PATH BLAAT
0187 export A B D
0188 local p=3  x  y='\'
0189 read x y z <<< $hallo
0190 unset B
0191 declare -a VAR1 VAR2 && exit
0192 declare less a && b
0193 declare a=(1 2)
0194 getopts :h:l::d arg
0195 read #comment
0196 let a=4+4 3+a b=c+3 d+3 d*4 # * is a glob
0197 
0198 # options are recoqnized:
0199 zip -f=file.zip
0200 ./configure  --destdir=/usr
0201 make  destdir=/usr/
0202 
0203 
0204 # [[ and [ correctly need spaces to be regarded as structure,
0205 # otherwise they are patterns (currently treated as normal text)
0206 if [ "$p" == "" ] ; then
0207         ls /usr/bin/[a-z]*
0208 elif [[ $p == 0 ]] ; then
0209         ls /usr/share/$p
0210 fi
0211 
0212 # Fixed:
0213 ls a[ab]*               # dont try to interprete as assignment with subscript (fixed)
0214 a[ab]
0215 a[ab]=sa
0216 
0217 
0218 # Here documents are difficult to catch:
0219 cat > myfile << __EOF__
0220 You're right, this is definitely no bash code
0221 But ls more $parameters should be expanded.
0222 __EOF__
0223 
0224 
0225 # quoted:
0226 cat << "EOF" | egrep "this" >&4   # the rest of the line is still considered bash source
0227 You're right, this is definitely no bash code
0228 But ls more $parameters should be expanded. :->
0229 EOF
0230 
0231 cat <<bla || exit
0232 bla bla
0233 bla
0234 
0235 
0236 # indented:
0237 if true
0238 then
0239         cat <<- EOF
0240                 Indented text with a $dollar or \$two
0241         EOF
0242 elif [ -d $file ]; then
0243         cat <<- "EOF"
0244                 Indented text without a $dollar
0245         EOF
0246 fi
0247 
0248 if ! { cmd1 && cmd2 ; }; then echo ok ; fi
0249 if ! cmd1 arg; then echo ok ; fi
0250 
0251 case 1 in
0252 2) echo xxx;
0253 ;;
0254 ?) foo || yyy ; foo abc || echo abc ;;
0255 1) echo yyy;
0256 esac
0257 
0258 ls #should be outside of case 1 folding block
0259 
0260 for i in `ls tests/auto/output/*.html`; do
0261     refFile=`echo $i | sed -e s,build,src, | sed -e s,output,reference, | sed -e s,.html,.ref.html,`
0262     cp -v $i $refFile
0263 done
0264 
0265 ## >Settings >Configure Kate >Fonts & Colors >Highlitghing Text Styles >Scripts/Bash >Option >Change colors to some distinct color
0266 ## 1- In following line the -ucode should not be colored as option
0267 
0268 pacman -Syu --needed intel-ucode grub
0269 pacman -syu --needed intel-ucode grub
0270 
0271 # Braces (bug ##387915)
0272 [[ $line_name =~ \{([0-9]{1,})\}\{([0-9]{1,})\}(.*) ]]
0273 [[ $name =~ (.*)_(S[0-9]{2})(E[0-9]{2,3}[a-z]{0,1})_(.*) ]]
0274 # Comments in Braces (bug 450878)
0275 [[ # comment 1
0276    1 == 1 # comment 2
0277    # comment 3
0278 ]]
0279 
0280 rm /data/{hello1,hello2}/input/{bye1,$bye2}/si{a,${b},c{k,p{e,a}}}/*.non
0281 rm /data/{aa,{e,i}t{b,c} # Not closed
0282 rm /data/{aa,{e,i}t{b,c}}
0283 rm /data/{aa,{i}}
0284 rm /data{aa{bb{cc{dd}}}}
0285 rm /data{aaa`aaa}aa`aaa}a
0286 
0287 ${array[0]: -7 : +  22  }  ${array[1]: num  }
0288 ${parameter##word} ${parameter%%word} ${parameter^^pattern} ${parameter,,pattern} ${parameter@operator}
0289 
0290 # TODO `
0291 
0292 # commands
0293 abc
0294 cp
0295 :
0296 .
0297 :#nokeyword
0298 path/cmd
0299 ec\
0300 ho
0301 2
0302 {ab}c
0303 {a,b}c
0304 'a'c
0305 $ab
0306 ${ab}c
0307 \ a
0308 !a
0309 {ab}[
0310 {a,b}[
0311 'a'[
0312 \ [
0313 !a[
0314 a{}d
0315 a{bc}d
0316 a{b,c}d
0317 a'b'c
0318 a$bc
0319 a${bc}d
0320 a\ b
0321 a!b
0322 a{}[
0323 a{bc}[
0324 a{b,c}[
0325 a'b'[
0326 a\ [
0327 a!b[
0328 
0329 # commands + params
0330 shortopt -ol -f/fd/fd -hfd/fds - -ol'a'b -f'a'/fd/fd -h'a'fd/fds
0331 longopt --long-a --long-b=value --file=* --file=file* --file=dir/file
0332 longopt --long-a'a'b --long'a'-b=value --fi'a'le=*
0333 noopt 3 3d -f -- -f --xx dir/file
0334 opt param#nocomment ab'a'cd [[ param ]] } { ~a .a #comments
0335 path path/file dir/ / // 3/f a@/ 'a'/b d/'a'b a\ d/f f/f\
0336 ile
0337 path ~ ~/ ~a/ . .. ./a ../a
0338 path /path/* /path/f* /path/f@ /path/f@(|) {a/b} a{b}/c a/b{c} a/{b} a/{b}c
0339 glob ? * ?f *f f* f? **/ ~/* ~* /path/f* 'a'* 'a'f/?
0340 extglob @ @(*) @(f*|f??(f)) f!(+(?(@(*(f)f)f)f)f)f @'a'@(|) a@(?)
0341 subs f! f!! f!s 'a'!s \( $v {a,b} {a} {a}/d {a\,} {a,} {a,\},b} ds/{a,b}sa/s
0342 2 - f -f
0343 !a -f
0344 'a' -f
0345 $a -f
0346 ! cmd
0347 
0348 # coproc command (#460301)
0349 coproc ls thisfiledoesntexist 2>&1
0350 coproc { ls thisfiledoesntexist; read; } 2>&1
0351 coproc mycoproc { awk '{print "foo" $0;fflush()}'; } >&3
0352 
0353 # redirections (prefix)
0354 <<<s cat
0355 <<<'s' cat
0356 <<<'s's cat
0357 <<<s's's cat
0358 <<<s${s}s cat
0359 <<< s${s}s cat
0360 >&2 cat
0361 <f cat
0362 2>3 cat
0363 2>&3 cat
0364 2>& 3 cat
0365 2>f cat
0366 &>f cat
0367 
0368 # redirections
0369 cat f>2
0370 cat d/f>2
0371 cat d/f >2
0372 cat d/f >& 2
0373 cat >2 d/f
0374 cat > 2
0375 cat <(echo) <(echo a) <(echo a/f) <(echo ) <(echo a ) <(echo a/f )
0376 cat 2>&1 &>f &>>f 2<&1- 2<>f 2<<heredoc
0377 bla bla
0378 heredoc
0379 <<-'h' cat
0380 bla
0381 h
0382 <<"'" cat
0383 bla
0384 '
0385 r=$(xxx $@ 2>&1)
0386 
0387 # branches
0388 cat a|cat
0389 cat a&cat
0390 cat a||cat
0391 cat a&&cat
0392 cat a;cat
0393 cat a | cat
0394 cat a & cat
0395 cat a || cat
0396 cat a && cat
0397 cat a ; cat
0398 cat a'a';cat
0399 
0400 # substitutions
0401 echo '' 'a' '\' "" "a" "\\" "$a" "a""a"'a''a' a'b'c a"b"c a$'\n'c
0402 echo a!bc a{a}b a{b,c}d a{b,{d,e}}d a\ b
0403 echo a$bc a$b/c a${b}c a$((b-3))c a$(b)c a$(a b c)c
0404 echo ${a[*]} ${a[@]} ${a[${b}]} ${a:-x$z} ${a-x} ${a/g} ${a//f/f} ${a//f*/f*}
0405 echo ${a^^l*} ${a,} ${!a} ${#a[1]} ${a:1:$b} $((++i,i--))
0406 echo "${var#lo+(r)em}" x "${var#+(r)em}" x
0407 echo "${var#refs/heads}" x "${var#refs}" x
0408 
0409 [ a ]
0410 [ -f f'f'f ]
0411 [ -f f]'f'f] ]
0412 [ -t 13 ]
0413 [ -t 13] ]
0414 [ -t 13] ]
0415 [ -v abc ]
0416 [ -z abc ]
0417 [ abc -ef abc ]
0418 [ abc -ef abc ]
0419 [ abc-ef -ef abc-ef ]
0420 [ abc == abc ]
0421 [ abc < abc ]
0422 [ abc -eq abc ]
0423 [[ abc -eq abc ]]
0424 [ 1+2 -eq 1+2 ]
0425 [[ 1+2 -eq 1+2 ]]
0426 [ a = b c ]
0427 [[ a = b c ]]
0428 [ -z 1 -a 1 -eq 1 ]
0429 [ 2 -eq 1 -o 1 -eq 1 ]
0430 [[ x =~ a(b c|$)' '{1,}[a[.digit.]] ]]
0431 [[ x =~ [ ] ]]
0432 [[ x =~ ([ ]) ]]
0433 [[ x =~ [ ]]
0434 [[ x =~ ([) ]]
0435 [[ (a =~ a) ]]
0436 [[ a =~ a || a -eq 2 ]]
0437 [[ (a =~ a) || a -eq 2 ]]
0438 [[ (0 -le $b) ]]
0439 [[ ( 0 -le $b ) ]]
0440 [[ ( 0 -le $b || $b -le 100 ) ]]
0441 [[ a<b ]]
0442 [[ a <b ]]
0443 [[ a< b ]]
0444 [[ a < b ]]
0445 [[(! -d .)]]
0446 [[ ! -d . ]]
0447 [[ !(-d .) ]]
0448 [[ -f a || -f b ]]
0449 [[ -f a||-f b ]]
0450 [[ ! (a -eq b) ]]
0451 [ -d `echo .`] ]
0452 [[ -d `echo .`]] ]]
0453 [[ a != b && ${a}a = b${b} ]]
0454 [[
0455   1 -eq 2
0456 ]]
0457 [[ -&&- ]]
0458 [[ ]]
0459 [[ -f ]]
0460 [[ -f [0-9a] ]]
0461 [[ ?*[0-9] = [^0-9] ]]
0462 [[ -f = ?*[0-9] ]]
0463 [[ ?*[0-9] = ?*[0-9] ]]
0464 [[ a/sa[s = dsad?*[0-9]dsa$ds ]]
0465 [[ a/sa[s = dsad?*[0-9]ds/a$ds ]]
0466 [[ a =~ [12]a([!d]a?s[x[:alnum:]]|d?)p ]]
0467 
0468 [[ #comm1
0469  #comm2
0470  p[1] == p[2]
0471  #comm3
0472  #comm4
0473 ]]
0474 
0475 [[ #comm1
0476  #comm2
0477  -f p[2]
0478  #comm3
0479  #comm4
0480 ]]
0481 
0482 ((3+1+a+$c*(x) & 0x43422fd+03-085/23#D9a@_^8))
0483 ((1/(2-(a-4))))
0484 
0485 # they are not arithmetic evaluations...
0486 ((cmd && cmd) || cmd)
0487 $((cmd && cmd) || cmd)
0488 ((cmd &&
0489 cmd) || cmd)
0490 $((cmd &&
0491 cmd) || cmd)
0492 
0493 { echo
0494     echo
0495 }
0496 { echo ; }
0497 (echo ; echo)
0498 (echo
0499     echo)
0500 (echo a)
0501 ({ echo plop;})
0502 [ a -eq 2 ] || [ a -eq 2] ] && [[ a -eq 2 ]] || [[ a != b ]];
0503 [ a -eq 2 ]||[ a -eq 2] ]&&[[ a -eq 2 ]]||[[ a != b ]];
0504 test a -eq b
0505 
0506 # functions
0507 a() { echo x; }
0508 a  () { echo x; }
0509 function f { echo x; }
0510 kde.org() { echo x; }
0511 --func() { echo x; }
0512 
0513 # variables
0514 a=(a b c)
0515 a='a'
0516 a+=b
0517 a[1]='a'
0518 a[$i]='x'
0519 a[$((
0520     2+4
0521 ))]='x'
0522 a=([a]=2 `echo` -s > 'ds')
0523 a=(#comment
0524 value#nocomment #comment)
0525 )
0526 a=a cat
0527 a=`ls` cat
0528 
0529 # errors
0530 a a(s) a
0531 
0532 # control structure
0533 for name in a b c {d,e} ; do echo ; done
0534 for name; do echo ; done
0535 for name do echo ; done
0536 for ((i=0;i<5;++i)) ; do echo $i ; done
0537 select name in a ; do echo ; done
0538 select name; do echo ; done
0539 if : ; then echo ; elif [[ : ]] ; then echo ; else echo ; fi
0540 while : || : ; do echo ; done
0541 until : ; : ; do echo ; done
0542 case a in a) esac
0543 case a in a) echo ; esac
0544 case pwd in (patt1) echo ; echo ;; (patt*) echo ;;& patt?|patt) echo ;&
0545 patt) echo ;; esac
0546 
0547 for name in a
0548  b c ;
0549 do
0550 echo
0551 done
0552 
0553 case a in
0554   a\( | b*c? ) echo
0555   (b$c) # no pattern
0556   ;;
0557   (b$c) ;;
0558   # no pattern
0559   (b$c)
0560 esac
0561 
0562 case "$1" in
0563  "a") run_a|&a;;
0564  "b") run_b;;
0565  "c") run_c;;
0566  *) echo "Plase choose between 'a', 'b' or 'c'" && exit 1;;
0567 esac