<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE language
[
    <!ENTITY tab      "&#009;">
    <!ENTITY funcname "([^&_fragpathseps;}=#$]|[+!@](?!\())([^&_fragpathseps;}=$]*+([+!@](?!\())?+)*+">
    <!ENTITY varname  "[A-Za-z_][A-Za-z0-9_]*">
    <!ENTITY eos      "(?=$|[ &tab;])">                 <!-- eol or space following -->
    <!ENTITY eoexpr   "(?=$|[ &tab;&lt;>|&amp;;)])">

    <!ENTITY substseps  "${'&quot;`\\">
    <!ENTITY symbolseps "&lt;>|&amp;;()"> <!-- see man bash -->
    <!ENTITY wordseps   " &tab;&symbolseps;"> <!-- see man bash -->

    <!ENTITY bq_string  "`[^`]*+`">
    <!ENTITY sq_string  "'[^']*+'">
    <!ENTITY dq_string  "&quot;(?:[^&quot;\\`]*+|&bq_string;|\\.)*+&quot;">
    <!ENTITY strings    "(?:&sq_string;|&dq_string;|&bq_string;)">

    <!ENTITY globany    "\[(?:[^&wordseps;&quot;'`\\\[\]]+|\\.|&strings;|\[:\w+:\]|\[)*\]">

    <!ENTITY next_is_globany    "(?:\^?\]\]|(?:\^?\]?)?(?:\\.|[^'&quot; &tab;&lt;>|&amp;;()\\[\]]+|&strings;|\[:\w+:\])+\])">
    <!ENTITY bracket_noglobany  "\[(?!&next_is_globany;)">

    <!ENTITY _fragpathseps  "*?+!@&wordseps;&substseps;">
    <!ENTITY _fragpathnosep "(?:[+!@](?!\()|\\.|&_brace_noexpansion;)?+">
    <!ENTITY path       "(?:[^&_fragpathseps;\[]*+&_fragpathnosep;)*+">
    <!ENTITY fragpath   "(?:[^&_fragpathseps;\[/]*+&_fragpathnosep;)*+">
    <!ENTITY opt        "(?:[^&_fragpathseps;\[=/]*+&_fragpathnosep;)*+">
    <!ENTITY pathpart   "(?:~|\.\.?|&fragpath;)(?:/&path;|(?=[*?]|[+!@]\(|&fragpath;(?:[/*?]|\[&next_is_globany;|[+!@]\()))|(?:~|\.\.?)(?=[&wordseps;]|$)">

    <!ENTITY _fragpathseps_alt  "*?+!@&substseps;}">
    <!ENTITY _fragpathnosep_alt "(?:[+!@](?!\()|\\.)?+">
    <!ENTITY path_alt       "(?:[^&_fragpathseps_alt;]*+&_fragpathnosep_alt;)*+">
    <!ENTITY fragpath_alt   "(?:[^&_fragpathseps_alt;/]*+&_fragpathnosep_alt;)*+">
    <!ENTITY opt_alt        "(?:[^&_fragpathseps_alt;=/]*+&_fragpathnosep_alt;)*+">
    <!ENTITY pathpart_alt   "(?:~|\.\.?|&fragpath_alt;)(?:/&path_alt;|(?=[*?]|[+!@]\(|&fragpath_alt;(?:[/*?]|[+!@]\()))|(?:~|\.\.?)(?=\}|$)">

    <!-- Path only with / -->
    <!ENTITY path_with_sep_text  "[^?*+!@&wordseps;'&quot;`\\/]">
    <!ENTITY path_with_sep_text2 "[^?*+!@()'&quot;`\\/]">
    <!ENTITY path_with_sep_expr  "\\.|&strings;|&globany;|[?*+](?!\()">
    <!ENTITY path_with_sep_spe   "(~|\.\.?)($|[/ &tab;&lt;>|&amp;;)])">
    <!ENTITY path_with_sep_sub   "[?*+!@]\((&path_with_sep_text2;++|&path_with_sep_expr;)*+(\)|(?=/))">
    <!ENTITY path_with_sep "/|&path_with_sep_spe;|(&path_with_sep_text;++|&path_with_sep_expr;|&path_with_sep_sub;)*+/">

    <!ENTITY _braceexpansion_spe     " &tab;&lt;>|&amp;;{}\\`'&quot;$">
    <!ENTITY _brace_noexpansion       "\{[^&_braceexpansion_spe;,]*+\}">
    <!ENTITY _braceexpansion_var     "\$(?:\{[^\[\]&_braceexpansion_spe;]*+(?:\[[*@a-zA-Z0-9]\])\})?">
    <!ENTITY _braceexpansion_string  "'[^']*'|&quot;([^&quot;\`]*+|`[^`]*`)*+&quot;">
    <!ENTITY _braceexpansion_elems   "\\.|`[^`]*`|&_braceexpansion_string;|&_braceexpansion_var;|&_brace_noexpansion;">
    <!ENTITY _braceexpansion_consume "&_braceexpansion_elems;|{(?:[^&_braceexpansion_spe;,]++|&_braceexpansion_elems;)*?}|(?R)?+">
    <!ENTITY _braceexpansion "(?:[^&_braceexpansion_spe;,]++|&_braceexpansion_consume;)*?,(?:[^&_braceexpansion_spe;]++|&_braceexpansion_consume;)*?}">
    <!ENTITY braceexpansion "{&_braceexpansion;">

    <!ENTITY heredocq "(?|&quot;([^&quot;]+)&quot;|'([^']+)'|\\(.[^&wordseps;&substseps;]*))">

    <!ENTITY arithmetic_as_subshell "\(((?:[^`'&quot;()$]++|\$\{[^`'&quot;(){}$]+\}|\$(?=[^{`'&quot;()])|`[^`]*+`|\((?1)(?:[)]|(?=['&quot;])))++)(?:[)](?=$|[^)])|[&quot;'])">

    <!ENTITY unary_operators  "-[abcdefghkprstuwxGLNOSovRnz](?=\\?$|[ &tab;])">
    <!ENTITY binary_operators "(?:-(?:e[fq]|[nolg]t|[nlg]e)|==?|!=)(?=\\?$|[ &tab;])">

    <!ENTITY dblbracket_close "\]\](?=($|[ &tab;;|&amp;)]))">

    <!ENTITY weakDeliminatorSymbols "^&#37;#[]$.{}:-/">
]>

<!--
https://git.savannah.gnu.org/cgit/bash.git/tree/NEWS
current: bash-5.2
-->

<language
    name="Bash"
    version="54"
    kateversion="5.79"
    section="Scripts"
    extensions="*.sh;*.bash;*.ebuild;*.eclass;*.exlib;*.exheres-0;.bashrc;.bash_profile;.bash_login;.profile;PKGBUILD;APKBUILD"
    mimetype="application/x-shellscript"
    casesensitive="1"
    author="Wilbert Berendsen (wilbert@kde.nl)"
    license="LGPL"
  >

<!-- (c) 2004 by Wilbert Berendsen (wilbert@kde.nl)
    Changes by Matthew Woehlke (mw_triad@users.sourceforge.net)
    Changes by Sebastian Pipping (webmaster@hartwork.org)
    Changes by Luiz Angelo Daros de Luca (luizluca@gmail.com)
    Released under the LGPL, part of kdelibs/kate -->

  <highlighting>
    <list name="keywords">
      <item>break</item>
      <item>case</item>
      <item>continue</item>
      <item>do</item>
      <item>done</item>
      <item>elif</item>
      <item>else</item>
      <item>esac</item>
      <item>fi</item>
      <item>for</item>
      <item>function</item>
      <item>if</item>
      <item>in</item>
      <item>return</item>
      <item>select</item>
      <item>then</item>
      <item>until</item>
      <item>while</item>
    </list>

    <list name="builtins">
      <item>.</item>
      <item>:</item>
      <item>source</item>
      <item>alias</item>
      <item>bg</item>
      <item>bind</item>
      <item>builtin</item>
      <item>cd</item>
      <item>caller</item>
      <item>command</item>
      <item>compgen</item>
      <item>complete</item>
      <item>coproc</item>
      <item>dirs</item>
      <item>disown</item>
      <item>echo</item>
      <item>enable</item>
      <item>eval</item>
      <item>exec</item>
      <item>exit</item>
      <item>fc</item>
      <item>fg</item>
      <item>hash</item>
      <item>help</item>
      <item>history</item>
      <item>jobs</item>
      <item>kill</item>
      <item>logout</item>
      <item>popd</item>
      <item>printf</item>
      <item>pushd</item>
      <item>pwd</item>
      <item>set</item>
      <item>shift</item>
      <item>shopt</item>
      <item>suspend</item>
      <item>test</item>
      <item>time</item>
      <item>times</item>
      <item>trap</item>
      <item>type</item>
      <item>ulimit</item>
      <item>umask</item>
      <item>unalias</item>
      <item>wait</item>
    </list>

    <list name="builtins_var">
      <item>export</item>
      <item>declare</item>
      <item>getopts</item>
      <item>let</item>
      <item>local</item>
      <item>read</item>
      <item>readonly</item>
      <item>typeset</item>
      <item>unset</item>
    </list>

    <list name="unixcommands">
      <!-- /bin -->
      <item>arch</item>
      <item>awk</item>
      <item>b2sum</item>
      <item>base32</item>
      <item>base64</item>
      <item>bash</item>
      <item>bunzip2</item>
      <item>bzcat</item>
      <item>bzcmp</item>
      <item>bzdiff</item>
      <item>bzegrep</item>
      <item>bzfgrep</item>
      <item>bzgrep</item>
      <item>bzip2</item>
      <item>bzip2recover</item>
      <item>bzless</item>
      <item>bzmore</item>
      <item>cat</item>
      <item>chattr</item>
      <item>chcon</item>
      <item>chgrp</item>
      <item>chmod</item>
      <item>chown</item>
      <item>chvt</item>
      <item>cksum</item>
      <item>cp</item>
      <item>crontab</item>
      <item>csplit</item>
      <item>date</item>
      <item>dd</item>
      <item>deallocvt</item>
      <item>df</item>
      <item>dir</item>
      <item>dircolors</item>
      <item>dmesg</item>
      <item>dnsdomainname</item>
      <item>domainname</item>
      <item>du</item>
      <item>dumpkeys</item>
      <item>ed</item>
      <item>egrep</item>
      <item>expand</item>
      <item>false</item>
      <item>fgconsole</item>
      <item>fgrep</item>
      <item>fold</item>
      <item>fuser</item>
      <item>gawk</item>
      <item>getkeycodes</item>
      <item>gocr</item>
      <item>grep</item>
      <item>groff</item>
      <item>groups</item>
      <item>gunzip</item>
      <item>gzexe</item>
      <item>gzip</item>
      <item>hostid</item>
      <item>hostname</item>
      <item>iconv</item>
      <item>igawk</item>
      <item>install</item>
      <item>kbd_mode</item>
      <item>kbdrate</item>
      <item>killall</item>
      <item>last</item>
      <item>lastb</item>
      <item>link</item>
      <item>ln</item>
      <item>loadkeys</item>
      <item>loadunimap</item>
      <item>login</item>
      <item>ls</item>
      <item>lsattr</item>
      <item>lsmod</item>
      <item>lsmod.old</item>
      <item>lzcat</item>
      <item>lzcmp</item>
      <item>lzdiff</item>
      <item>lzegrep</item>
      <item>lzfgrep</item>
      <item>lzgrep</item>
      <item>lzless</item>
      <item>lzma</item>
      <item>lzmainfo</item>
      <item>lzmore</item>
      <item>mapscrn</item>
      <item>md5sum</item>
      <item>mesg</item>
      <item>mkdir</item>
      <item>mkfifo</item>
      <item>mknod</item>
      <item>mktemp</item>
      <item>more</item>
      <item>mount</item>
      <item>mv</item>
      <item>nano</item>
      <item>netstat</item>
      <item>nisdomainname</item>
      <item>nproc</item>
      <item>nroff</item>
      <item>numfmt</item>
      <item>openvt</item>
      <item>paste</item>
      <item>pathchk</item>
      <item>pgawk</item>
      <item>pidof</item>
      <item>ping</item>
      <item>pinky</item>
      <item>printenv</item>
      <item>ps</item>
      <item>pstree</item>
      <item>ptx</item>
      <item>rbash</item>
      <item>readlink</item>
      <item>realpath</item>
      <item>red</item>
      <item>resizecons</item>
      <item>rm</item>
      <item>rmdir</item>
      <item>run-parts</item>
      <item>runcon</item>
      <item>sash</item>
      <item>sed</item>
      <item>setfont</item>
      <item>setkeycodes</item>
      <item>setleds</item>
      <item>setmetamode</item>
      <item>setserial</item>
      <item>sh</item>
      <item>sha1sum</item>
      <item>sha224sum</item>
      <item>sha256sum</item>
      <item>sha384sum</item>
      <item>sha512sum</item>
      <item>showkey</item>
      <item>shred</item>
      <item>shuf</item>
      <item>sleep</item>
      <item>ssed</item>
      <item>stat</item>
      <item>stdbuf</item>
      <item>stty</item>
      <item>su</item>
      <item>sync</item>
      <item>tar</item>
      <item>tempfile</item>
      <item>timeout</item>
      <item>touch</item>
      <item>tput</item>
      <item>troff</item>
      <item>true</item>
      <item>truncate</item>
      <item>tty</item>
      <item>umount</item>
      <item>uname</item>
      <item>unexpand</item>
      <item>unicode_start</item>
      <item>unicode_stop</item>
      <item>unlink</item>
      <item>unlzma</item>
      <item>unxz</item>
      <item>utmpdump</item>
      <item>uuidgen</item>
      <item>vdir</item>
      <item>vi</item>
      <item>wall</item>
      <item>wc</item>
      <item>xz</item>
      <item>xzcat</item>
      <item>ypdomainname</item>
      <item>zcat</item>
      <item>zcmp</item>
      <item>zdiff</item>
      <item>zegrep</item>
      <item>zfgrep</item>
      <item>zforce</item>
      <item>zgrep</item>
      <item>zless</item>
      <item>zmore</item>
      <item>znew</item>
      <item>zsh</item>

      <!-- some from /usr/bin -->
      <item>aclocal</item>
      <item>aconnect</item>
      <item>aplay</item>
      <item>apm</item>
      <item>apmsleep</item>
      <item>apropos</item>
      <item>ar</item>
      <item>arecord</item>
      <item>as</item>
      <item>as86</item>
      <item>autoconf</item>
      <item>autoheader</item>
      <item>automake</item>
      <item>basename</item>
      <item>bc</item>
      <item>bison</item>
      <item>c++</item>
      <item>cal</item>
      <item>cc</item>
      <item>cdda2wav</item>
      <item>cdparanoia</item>
      <item>cdrdao</item>
      <item>cd-read</item>
      <item>cdrecord</item>
      <item>chfn</item>
      <item>chroot</item>
      <item>chsh</item>
      <item>clear</item>
      <item>cmp</item>
      <item>co</item>
      <item>col</item>
      <item>comm</item>
      <item>cpio</item>
      <item>cpp</item>
      <item>cut</item>
      <item>dc</item>
      <item>diff</item>
      <item>diff3</item>
      <item>directomatic</item>
      <item>dirname</item>
      <item>env</item>
      <item>expr</item>
      <item>fbset</item>
      <item>file</item>
      <item>find</item>
      <item>flex</item>
      <item>flex++</item>
      <item>fmt</item>
      <item>free</item>
      <item>ftp</item>
      <item>funzip</item>
      <item>g++</item>
      <item>gc</item>
      <item>gcc</item>
      <item>clang</item>
      <item>clang++</item>
      <item>valgrind</item>
      <item>xdg-open</item>
      <item>cmake</item>
      <item>qmake</item>
      <item>svn</item>
      <item>git</item>
      <item>rsync</item>
      <item>gdb</item>
      <item>getent</item>
      <item>getopt</item>
      <item>gettext</item>
      <item>gettextize</item>
      <item>gimp</item>
      <item>gimp-remote</item>
      <item>gimptool</item>
      <item>gmake</item>
      <item>gs</item>
      <item>head</item>
      <item>hexdump</item>
      <item>id</item>
      <item>join</item>
      <item>ld</item>
      <item>ld86</item>
      <item>ldd</item>
      <item>less</item>
      <item>lex</item>
      <item>locate</item>
      <item>lockfile</item>
      <item>logname</item>
      <item>lp</item>
      <item>lpr</item>
      <item>lynx</item>
      <item>m4</item>
      <item>make</item>
      <item>man</item>
      <item>msgfmt</item>
      <item>namei</item>
      <item>nasm</item>
      <item>nawk</item>
      <item>nice</item>
      <item>nl</item>
      <item>nm</item>
      <item>nm86</item>
      <item>nmap</item>
      <item>nohup</item>
      <item>nop</item>
      <item>od</item>
      <item>passwd</item>
      <item>patch</item>
      <item>pcregrep</item>
      <item>pcretest</item>
      <item>perl</item>
      <item>perror</item>
      <item>pr</item>
      <item>procmail</item>
      <item>prune</item>
      <item>ps2ascii</item>
      <item>ps2epsi</item>
      <item>ps2frag</item>
      <item>ps2pdf</item>
      <item>ps2ps</item>
      <item>psbook</item>
      <item>psmerge</item>
      <item>psnup</item>
      <item>psresize</item>
      <item>psselect</item>
      <item>pstops</item>
      <item>rcs</item>
      <item>rev</item>
      <item>scp</item>
      <item>seq</item>
      <item>setterm</item>
      <item>size</item>
      <item>size86</item>
      <item>skill</item>
      <item>slogin</item>
      <item>snice</item>
      <item>sort</item>
      <item>sox</item>
      <item>split</item>
      <item>ssh</item>
      <item>ssh-add</item>
      <item>ssh-agent</item>
      <item>ssh-keygen</item>
      <item>ssh-keyscan</item>
      <item>strings</item>
      <item>strip</item>
      <item>sudo</item>
      <item>suidperl</item>
      <item>sum</item>
      <item>tac</item>
      <item>tail</item>
      <item>tee</item>
      <item>tr</item>
      <item>tsort</item>
      <item>uniq</item>
      <item>unzip</item>
      <item>updatedb</item>
      <item>updmap</item>
      <item>uptime</item>
      <item>users</item>
      <item>vmstat</item>
      <item>w</item>
      <item>wget</item>
      <item>whatis</item>
      <item>whereis</item>
      <item>which</item>
      <item>who</item>
      <item>whoami</item>
      <item>write</item>
      <item>xargs</item>
      <item>yacc</item>
      <item>yes</item>
      <item>zip</item>
      <item>zsoelim</item>

      <!-- others -->
      <item>dcop</item>
      <item>kdialog</item>
      <item>kfile</item>
      <item>xhost</item>
      <item>xmodmap</item>
      <item>xset</item>
    </list>


    <contexts>
      <context attribute="Normal Text" lineEndContext="#stay" name="Start" fallthroughContext="Command">
        <IncludeRules context="BashOneLine"/>
      </context>

      <!-- used by other syntaxes -->
      <context attribute="Normal Text" lineEndContext="#pop" name="FindOneLineBackq" fallthroughContext="#pop">
        <DetectChar attribute="Backquote" context="OneLineBackq" char="`"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#stay" name="OneLineBackq" fallthroughContext="Command">
        <DetectChar attribute="Backquote" context="#pop" char="`"/>
        <IncludeRules context="Start"/>
      </context>

      <context attribute="Normal Text" lineEndContext="#pop" name="BashOneLine" fallthroughContext="Command">
        <DetectSpaces attribute="Normal Text" context="#stay"/>
        <DetectChar attribute="Comment" context="Comment" char="#"/>
        <!-- start expression in double parentheses -->
        <Detect2Chars context="ExprDblParenOrSubShell" char="(" char1="(" lookAhead="1"/>
        <!-- start a subshell -->
        <DetectChar attribute="Keyword" context="SubShell" char="(" beginRegion="subshell"/>
        <!-- start expression in single/double brackets -->
        <DetectChar context="MaybeBracketExpression" char="[" lookAhead="1"/>
        <!-- start a group command or BraceExpansion with { -->
        <DetectChar context="MaybeGroup" char="{" lookAhead="1"/>

        <!-- handle ` -->
        <DetectChar attribute="Backquote" context="CommandBackq" char="`"/>

        <!-- &> and &>> redirection -->
        <StringDetect attribute="Redirection" context="WordRedirection" String="&amp;>>"/>
        <Detect2Chars attribute="Redirection" context="FdRedirection" char="&amp;" char1=">"/>

        <!-- handle branche conditions -->
        <Detect2Chars attribute="Control" context="#stay" char="&amp;" char1="&amp;"/>
        <Detect2Chars attribute="Control" context="#stay" char="|" char1="|"/>

        <!-- handle &, |, ; -->
        <AnyChar attribute="Control" context="#stay" String="&amp;|;"/>

        <!-- handle variable assignments -->
        <RegExpr attribute="Variable" context="VarAssign" String="&varname;(?=\+?=|\[(?:$|[^]]))"/>
        <!-- handle keywords -->
        <keyword context="DispatchKeyword" String="keywords" lookAhead="1"/>
        <!-- handle commands that have variable names as argument -->
        <keyword attribute="Builtin" context="VarName" String="builtins_var" lookAhead="1"/>
        <!-- mark function definitions without function keyword -->
        <RegExpr attribute="Function" context="#stay" String="&funcname;[ &tab;]*\(\)"/>
        <!-- Special case for `: << '#BLOCK-COMMENT' form of "multiline" comments-->
        <RegExpr attribute="Normal Text" context="PreHereDocMLComment" String="^:[ &tab;]+&lt;&lt;[ &tab;]*'#([^']+)'$" lookAhead="1" column="0"/>
        <WordDetect attribute="Builtin" context="Coproc" String="coproc"/>
        <keyword attribute="Builtin" context="CommandArgs" String="builtins"/>
        <keyword attribute="Command" context="CommandArgs" String="unixcommands"/>

        <!-- handle redirection -->
        <AnyChar context="CommandMaybeRedirection" String="&lt;&gt;0123456789" lookAhead="1"/>

        <AnyChar attribute="Error" context="#stay" String=")}"/>

        <LineContinue attribute="Escape" context="#stay"/>

        <Detect2Chars attribute="Expression" context="#stay" char="!" char1=" "/>
      </context>
      <context attribute="Normal Text" lineEndContext="#pop" name="MaybeBracketExpression" fallthroughContext="#pop!Command">
        <!-- start expression in double brackets -->
        <RegExpr attribute="Keyword" context="#pop!ExprDblBracket" String="\[\[(?=$|[ &tab;(])" beginRegion="expression"/>
        <!-- start expression in single brackets -->
        <RegExpr attribute="Builtin" context="#pop!ExprBracket" String="\[&eos;" beginRegion="expression"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#pop" name="MaybeGroup">
        <!-- start a group command with { -->
        <RegExpr attribute="Keyword" context="#pop!Group" String="\{&eos;" beginRegion="group"/>
        <DetectChar context="#pop!Command" char="{" lookAhead="1"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#pop" name="CommandMaybeRedirection" fallthroughContext="#pop!Command">
        <IncludeRules context="FindRedirection"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#pop" name="Return" fallthroughContext="#pop">
        <DetectSpaces attribute="Normal Text" context="#stay"/>
        <Int attribute="Decimal" context="#stay"/>
      </context>
      <!-- Comment consumes shell comments till EOL -->
      <context attribute="Comment" lineEndContext="#pop" name="Comment">
        <DetectSpaces attribute="Comment"/>
        <IncludeRules context="##Comments"/>
        <DetectIdentifier attribute="Comment" context="#stay"/>
      </context>

      <!-- Group is called after a { is encountered -->
      <context attribute="Normal Text" lineEndContext="#stay" name="Group" fallthroughContext="Command">
        <DetectChar context="MaybeGroupEnd" char="}" lookAhead="1"/>
        <IncludeRules context="Start"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#pop" name="MaybeGroupEnd">
        <!-- stop a group command with } -->
        <RegExpr attribute="Keyword" context="#pop#pop" String="\}&eoexpr;" endRegion="group"/>
        <DetectChar context="#pop!Command" char="}" lookAhead="1"/>
      </context>

      <context attribute="Normal Text" lineEndContext="#pop" name="Coproc" fallthroughContext="#pop">
        <DetectSpaces attribute="Normal Text"/>
        <LineContinue attribute="Escape" context="#stay"/>
        <RegExpr context="CoprocName" String="(\$?&varname;|\$\{&varname;\}|'&varname;'|&quot;(\$?&varname;|\$\{&varname;\}|[a-zA-Z0-9_])+&quot;)+(?=\s+\{($|\s))" lookAhead="1"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#stay" name="CoprocName">
        <DetectChar attribute="Keyword" context="#pop#pop!Group" char="{" beginRegion="group"/>
        <DetectSpaces attribute="Normal Text"/>
        <DetectIdentifier attribute="Normal Text"/>
        <IncludeRules context="FindWord"/>
      </context>

      <context attribute="Command" lineEndContext="#pop" name="Command" fallthroughContext="#pop">
        <DetectSpaces attribute="Normal Text" context="#pop!CommandArgs"/>
        <DetectChar context="CommandVariables" char="$" lookAhead="1"/>
        <IncludeRules context="FindStrings"/>
        <DetectChar context="#pop" char="`" lookAhead="1"/>
        <RegExpr attribute="OtherCommand" context="CommandName" String="(?:[^&wordseps;&substseps;]++|\\.)+"/>
        <LineContinue attribute="Escape" context="#stay"/>
        <DetectChar context="CommandMaybeBraceExpansion" char="{" lookAhead="1"/>
      </context>
      <context attribute="Command" lineEndContext="#pop#pop" name="CommandVariables">
        <IncludeRules context="DispatchVariables"/>
        <DetectChar attribute="OtherCommand" context="#pop" char="$"/>
      </context>
      <context attribute="Command" lineEndContext="#pop#pop" name="DispatchVariables">
        <IncludeRules context="DispatchSubstVariables"/>
        <IncludeRules context="DispatchStringVariables"/>
        <IncludeRules context="DispatchVarnameVariables"/>
      </context>
      <context attribute="Command" lineEndContext="#pop#pop" name="DispatchSubstVariables">
        <Detect2Chars attribute="Parameter Expansion" context="#pop!VarBraceStart" char="$" char1="{"/>
        <StringDetect context="#pop!ExprDblParenSubstOrSubstCommand" String="$((" lookAhead="1"/>
        <Detect2Chars attribute="Parameter Expansion" context="#pop!SubstCommand" char="$" char1="(" beginRegion="subshell"/>
      </context>
      <context attribute="Command" lineEndContext="#pop#pop" name="DispatchStringVariables">
        <Detect2Chars attribute="String SingleQ" context="#pop!StringEsc" char="$" char1="'"/>
        <Detect2Chars attribute="String Transl." context="#pop!StringDQ" char="$" char1="&quot;"/>
      </context>
      <context attribute="Command" lineEndContext="#pop#pop" name="DispatchVarnameVariables">
        <RegExpr attribute="Dollar Prefix" context="#pop!VarNamePrefixedWithDollar" String="\$(?=&varname;|[*@#?$!0-9-])"/>
      </context>
      <context attribute="Variable" lineEndContext="#pop" name="VarNamePrefixedWithDollar">
        <DetectIdentifier attribute="Variable" context="#pop"/>
        <AnyChar attribute="Variable" context="#pop" String="*@#?$!0123456789-"/>
      </context>
      <context attribute="OtherCommand" lineEndContext="#pop#pop" name="CommandName">
        <DetectSpaces attribute="Normal Text" context="#pop#pop!CommandArgs"/>
        <DetectIdentifier attribute="OtherCommand" context="#stay"/>
        <DetectChar context="CommandVariables" char="$" lookAhead="1"/>
        <IncludeRules context="FindStrings"/>
        <Detect2Chars attribute="Control" context="#pop#pop" char="&amp;" char1="&amp;"/>
        <Detect2Chars attribute="Control" context="#pop#pop" char="|" char1="|"/>
        <DetectChar attribute="Control" context="#pop#pop" char="|"/>
        <AnyChar context="#pop#pop" String=";)`" lookAhead="1"/>
        <AnyChar context="#pop#pop!CommandArgs" String="&amp;&lt;>" lookAhead="1"/>
        <!-- start expression in double parentheses -->
        <Detect2Chars attribute="Error" context="#pop#pop!ExprDblParen" char="(" char1="(" beginRegion="expression"/>
        <!-- start a subshell -->
        <DetectChar attribute="Error" context="#pop#pop!SubShell" char="(" beginRegion="subshell"/>
        <LineContinue attribute="Escape" context="#stay"/>
        <DetectChar context="#pop!CommandMaybeBraceExpansion" char="{" lookAhead="1"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#pop" name="CommandMaybeBraceExpansion">
        <IncludeRules context="DispatchBraceExpansion"/>
        <DetectChar attribute="OtherCommand" context="#pop" char="{"/>
      </context>

      <context attribute="Normal Text" lineEndContext="#stay" name="CommandBackq" fallthroughContext="Command">
        <DetectChar attribute="Backquote" context="#pop!CommandArgs" char="`"/>
        <DetectChar attribute="Comment" context="CommentBackq" char="#"/>
        <IncludeRules context="Start"/>
      </context>
      <!-- CommentBackq consumes shell comments till EOL or a backquote -->
      <context attribute="Comment" lineEndContext="#pop" name="CommentBackq">
        <DetectChar context="#pop" char="`" lookAhead="1"/>
        <IncludeRules context="Comment"/>
      </context>

      <!-- CommandArgs matches the items after a command -->
      <context attribute="Normal Text" lineEndContext="#pop" name="CommandArgs" fallthroughContext="CommandArg">
        <DetectSpaces attribute="Normal Text" context="#stay"/>

        <!-- &> and &>> redirection -->
        <StringDetect attribute="Redirection" context="WordRedirection" String="&amp;>>"/>
        <Detect2Chars attribute="Redirection" context="FdRedirection" char="&amp;" char1=">"/>

        <!-- handle &, |, ;, ` -->
        <AnyChar context="#pop" String="&amp;|;`" lookAhead="1"/>

        <!-- handle redirection -->
        <AnyChar context="CommandArgMaybeRedirection" String="&lt;&gt;0123456789" lookAhead="1"/>

        <DetectChar context="#pop" char=")" lookAhead="1"/>
        <DetectChar attribute="Error" context="#pop!SubShell" char="("/>
      </context>
      <context attribute="Normal Text" lineEndContext="#pop#pop" name="CommandArg" fallthroughContext="#pop!NormalOption">
        <!-- In command arguments, do not allow comments after escaped characters.
             This avoids highlighting comments within paths or other text. Ex: pathtext\ #no\ comment -->
        <DetectChar context="#pop#pop" char="#" lookAhead="1"/>
        <Detect2Chars attribute="Option" context="#pop!LongOption" char="-" char1="-"/>
        <DetectChar attribute="Option" context="#pop!ShortOption" char="-"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#pop" name="CommandArgMaybeRedirection" fallthroughContext="#pop!NormalOption">
        <IncludeRules context="FindRedirection"/>
      </context>

      <context attribute="Option" lineEndContext="#pop" name="ShortOption" fallthroughContext="#pop">
        <DetectChar attribute="Path" context="PathThenPop" char="/"/>
        <IncludeRules context="LongOption"/>
      </context>
      <context attribute="Option" lineEndContext="#pop" name="LongOption" fallthroughContext="#pop">
        <AnyChar context="#pop" String="&wordseps;`" lookAhead="1"/>
        <DetectChar attribute="Operator" context="#pop!NormalOption" char="="/>
        <IncludeRules context="FindWord"/>
        <IncludeRules context="FindGlobAndPop"/>
        <DetectChar context="OptionMaybeBraceExpansion" char="{" lookAhead="1"/>
        <DetectChar context="LongOptionMaybeGlobAny" char="[" lookAhead="1"/>
        <RegExpr attribute="Option" context="#stay" String="&opt;"/>
      </context>
      <context attribute="Option" lineEndContext="#pop#pop" name="LongOptionMaybeGlobAny" fallthroughContext="#pop">
        <IncludeRules context="FindGlobAny"/>
        <DetectChar attribute="Option" context="#pop" char="["/>
      </context>
      <context attribute="Normal Text" lineEndContext="#pop" name="NormalOption" fallthroughContext="#pop">
        <AnyChar context="#pop" String="&wordseps;`" lookAhead="1"/>
        <IncludeRules context="FindWord"/>
        <DetectChar context="NormalMaybeBraceExpansion" char="{" lookAhead="1"/>
        <IncludeRules context="FindNormalText"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#stay" name="FindNormalText">
        <IncludeRules context="FindGlobAndPop"/>
        <RegExpr attribute="Path" context="PathThenPop" String="&pathpart;"/>
        <DetectChar context="FindPathThenPopMaybeGlobAny" char="[" lookAhead="1"/>
        <RegExpr attribute="Normal Text" context="#stay" String="[^&wordseps;&substseps;\[]+"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#pop" name="OptionMaybeBraceExpansion">
        <IncludeRules context="DispatchBraceExpansion"/>
        <DetectChar attribute="Option" context="#pop" char="{"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#pop" name="NormalMaybeBraceExpansion">
        <IncludeRules context="DispatchBraceExpansion"/>
        <DetectChar attribute="Normal Text" context="#pop" char="{"/>
      </context>

      <context attribute="Normal Text" lineEndContext="#pop" name="AssumeEscape">
        <LineContinue attribute="Escape" context="#pop"/>
        <RegExpr attribute="Escape" context="#pop" String="\\."/>
      </context>

<!-- ====== The following rulessets are meant to be included ======== -->

      <!-- FindRedirection consumes shell redirection -->
      <context attribute="Normal Text" lineEndContext="#pop" name="FindRedirection">
        <RegExpr attribute="File Descriptor" context="#pop!AssumeRedirection" String="[0-9]++(?=[&lt;>])"/>
        <IncludeRules context="AssumeRedirection"/>
      </context>

      <!-- DispatchBraceExpansion consumes brace expansions -->
      <context attribute="Normal Text" lineEndContext="#pop" name="DispatchBraceExpansion">
        <!-- Only highlighting closed braces. The "BraceExpansion" context corrects
             the closure of braces and allows recursive braces (bug #387915). -->
        <RegExpr context="#pop!BraceExpansion" String="&braceexpansion;" lookAhead="1"/>
        <RegExpr attribute="Escape" context="#pop!SequenceExpression" String="{(?=([-+]?[0-9]+\.\.[-+]?[0-9]+|[a-zA-Z]\.\.[a-zA-Z])(\.\.[-+]?[0-9]+)?\})"/>
      </context>

      <!-- FindPathThenPopMaybeGlobAny consumes path -->
      <context attribute="Normal Text" lineEndContext="#pop#pop" name="FindPathThenPopMaybeGlobAny" fallthroughContext="#pop!PathThenPop">
        <IncludeRules context="FindGlobAny"/>
        <DetectChar attribute="Normal Text" context="#pop" char="["/>
      </context>
      <context attribute="Path" lineEndContext="#pop" name="FindGlobAndPop">
        <Detect2Chars attribute="Glob" context="ExtGlobAndPop" char="?" char1="("/>
        <Detect2Chars attribute="Glob" context="ExtGlobAndPop" char="*" char1="("/>
        <AnyChar attribute="Glob" context="PathThenPop" String="?*"/>
        <Detect2Chars attribute="Glob" context="ExtGlobAndPop" char="+" char1="("/>
        <Detect2Chars attribute="Glob" context="ExtGlobAndPop" char="@" char1="("/>
        <Detect2Chars attribute="Glob" context="ExtGlobAndPop" char="!" char1="("/>
      </context>
      <context attribute="Path" lineEndContext="#stay" name="ExtGlobAndPop">
        <DetectChar attribute="Glob" context="#pop!PathThenPop" char=")"/>
        <IncludeRules context="FindWord"/>
        <IncludeRules context="IncExtGlob"/>
      </context>
      <context attribute="Path" lineEndContext="#stay" name="FindExtGlob">
        <Detect2Chars attribute="Glob" context="RecursiveExtGlob" char="?" char1="("/>
        <Detect2Chars attribute="Glob" context="RecursiveExtGlob" char="*" char1="("/>
        <Detect2Chars attribute="Glob" context="RecursiveExtGlob" char="+" char1="("/>
        <Detect2Chars attribute="Glob" context="RecursiveExtGlob" char="@" char1="("/>
        <Detect2Chars attribute="Glob" context="RecursiveExtGlob" char="!" char1="("/>
        <AnyChar attribute="Glob" context="#stay" String="|?*"/>
      </context>
      <context attribute="Path" lineEndContext="#stay" name="RecursiveExtGlob">
        <DetectChar attribute="Glob" context="#pop" char=")"/>
        <IncludeRules context="FindWord"/>
        <IncludeRules context="IncExtGlob"/>
        <IncludeRules context="PathThenPopMaybeGlobAny"/>
      </context>
      <context attribute="Path" lineEndContext="#stay" name="IncExtGlob">
        <DetectIdentifier attribute="Path"/>
        <IncludeRules context="FindExtGlob"/>
        <DetectChar context="PathMaybeBraceExpansion" char="{" lookAhead="1"/>
      </context>
      <context attribute="Path" lineEndContext="#pop#pop" name="PathThenPop">
        <AnyChar context="#pop#pop" String="&wordseps;`" lookAhead="1"/>
        <IncludeRules context="FindWord"/>
        <IncludeRules context="FindExtGlob"/>
        <DetectChar context="PathMaybeBraceExpansion" char="{" lookAhead="1"/>
        <DetectChar context="PathThenPopMaybeGlobAny" char="[" lookAhead="1"/>
        <RegExpr attribute="Path" context="#stay" String="&path;"/>
      </context>
      <context attribute="Path" lineEndContext="#pop#pop" name="PathThenPopMaybeGlobAny" fallthroughContext="#pop">
        <IncludeRules context="FindGlobAny"/>
        <DetectChar attribute="Path" context="#pop" char="["/>
      </context>
      <context attribute="Path" lineEndContext="#pop" name="PathMaybeBraceExpansion" fallthroughContext="#pop">
        <IncludeRules context="DispatchBraceExpansion"/>
        <DetectChar attribute="Path" context="#pop" char="{"/>
      </context>

      <context attribute="Glob" lineEndContext="#stay" name="FindGlobAny">
        <RegExpr attribute="Glob" context="GlobAnyFlag" String="\[(?=&next_is_globany;)"/>
      </context>
      <context attribute="Pattern" lineEndContext="#pop" name="GlobAnyFlag" fallthroughContext="#pop!GlobAny">
        <DetectChar attribute="Glob" context="#pop!GlobAny" char="^"/>
      </context>
      <context attribute="Pattern" lineEndContext="#pop" name="GlobAny">
        <DetectIdentifier attribute="Pattern"/>
        <DetectChar context="AssumeEscape" char="\" lookAhead="1"/>
        <DetectChar attribute="Glob" context="#stay" char="-"/>
        <IncludeRules context="FindStrings"/>
        <DetectChar attribute="Glob" context="#pop" char="]"/>
        <Detect2Chars attribute="Glob" context="GlobClass" char="[" char1=":"/>
      </context>
      <context attribute="Glob" lineEndContext="#pop#pop" name="GlobClass">
        <DetectIdentifier attribute="Pattern"/>
        <Detect2Chars attribute="Glob" context="#pop" char=":" char1="]"/>
        <DetectChar attribute="Error" context="#pop" char="]"/>
      </context>

      <!-- FindPathThenPopInAlternateValue consumes path in ${xx:here}-->
      <context attribute="Normal Text" lineEndContext="#pop" name="FindPathThenPopInAlternateValue">
        <DetectChar attribute="Variable" char="&amp;"/>
        <Detect2Chars context="#pop!PathThenPopInAlternateValue" char="?" char1="(" lookAhead="1"/>
        <Detect2Chars context="#pop!PathThenPopInAlternateValue" char="*" char1="(" lookAhead="1"/>
        <Detect2Chars context="#pop!PathThenPopInAlternateValue" char="+" char1="(" lookAhead="1"/>
        <Detect2Chars context="#pop!PathThenPopInAlternateValue" char="@" char1="(" lookAhead="1"/>
        <Detect2Chars context="#pop!PathThenPopInAlternateValue" char="!" char1="(" lookAhead="1"/>
        <AnyChar attribute="Glob" context="#pop!PathThenPopInAlternateValue" String="?*"/>
        <RegExpr attribute="Path" context="#pop!PathThenPopInAlternateValue" String="&pathpart_alt;"/>
      </context>
      <context attribute="Path" lineEndContext="#pop#pop" name="PathThenPopInAlternateValue">
        <DetectChar attribute="Parameter Expansion" context="#pop" char="}"/>
        <IncludeRules context="FindWord"/>
        <Detect2Chars attribute="Glob" context="ExtGlobAndPopInAlternateValue" char="?" char1="("/>
        <Detect2Chars attribute="Glob" context="ExtGlobAndPopInAlternateValue" char="*" char1="("/>
        <Detect2Chars attribute="Glob" context="ExtGlobAndPopInAlternateValue" char="+" char1="("/>
        <Detect2Chars attribute="Glob" context="ExtGlobAndPopInAlternateValue" char="@" char1="("/>
        <Detect2Chars attribute="Glob" context="ExtGlobAndPopInAlternateValue" char="!" char1="("/>
        <AnyChar attribute="Glob" context="#stay" String="?*"/>
        <RegExpr attribute="Path" context="#stay" String="&path_alt;"/>
      </context>
      <context attribute="Path" lineEndContext="#stay" name="ExtGlobAndPopInAlternateValue">
        <DetectChar attribute="Glob" context="#pop" char=")"/>
        <DetectChar attribute="Error" context="#pop#pop" char="}"/>
        <IncludeRules context="FindWord"/>
        <IncludeRules context="FindExtGlobInAlternateValue"/>
      </context>
      <context attribute="Path" lineEndContext="#stay" name="FindExtGlobInAlternateValue">
        <DetectIdentifier attribute="Path"/>
        <Detect2Chars attribute="Glob" context="RecursiveExtGlobInAlternateValue" char="?" char1="("/>
        <Detect2Chars attribute="Glob" context="RecursiveExtGlobInAlternateValue" char="*" char1="("/>
        <Detect2Chars attribute="Glob" context="RecursiveExtGlobInAlternateValue" char="+" char1="("/>
        <Detect2Chars attribute="Glob" context="RecursiveExtGlobInAlternateValue" char="@" char1="("/>
        <Detect2Chars attribute="Glob" context="RecursiveExtGlobInAlternateValue" char="!" char1="("/>
        <AnyChar attribute="Glob" context="#stay" String="|?*"/>
      </context>
      <context attribute="Path" lineEndContext="#stay" name="RecursiveExtGlobInAlternateValue">
        <DetectChar attribute="Glob" context="#pop" char=")"/>
        <DetectChar context="#pop" char="}" lookAhead="1"/>
        <IncludeRules context="FindWord"/>
        <IncludeRules context="FindExtGlobInAlternateValue"/>
      </context>

      <context attribute="Pattern" lineEndContext="#stay" name="FindPattern">
        <Detect2Chars attribute="Glob" context="ExtPattern" char="?" char1="("/>
        <Detect2Chars attribute="Glob" context="ExtPattern" char="*" char1="("/>
        <Detect2Chars attribute="Glob" context="ExtPattern" char="+" char1="("/>
        <Detect2Chars attribute="Glob" context="ExtPattern" char="@" char1="("/>
        <Detect2Chars attribute="Glob" context="ExtPattern" char="!" char1="("/>
        <AnyChar attribute="Glob" context="#stay" String="?*"/>
      </context>
      <context attribute="Pattern" lineEndContext="#stay" name="ExtPattern">
        <DetectIdentifier attribute="Pattern"/>
        <DetectChar attribute="Glob" context="#stay" char="|"/>
        <IncludeRules context="FindWord"/>
        <DetectChar attribute="Glob" context="#pop" char=")"/>
        <IncludeRules context="FindPattern"/>
      </context>

      <context attribute="Normal Text" lineEndContext="#pop" name="VarAssign" fallthroughContext="#pop">
        <DetectChar attribute="Parameter Expansion Operator" context="Subscript" char="["/>
        <DetectChar attribute="Operator" context="#pop!Assign" char="="/>
        <Detect2Chars attribute="Operator" context="#pop!Assign" char="+" char1="="/>
      </context>

      <context attribute="Normal Text" lineEndContext="#pop" name="DispatchKeyword">
        <!-- match do and if blocks -->
        <Detect2Chars attribute="Control Flow" context="#pop!NotCond" char="i" char1="f" beginRegion="if"/>
        <Detect2Chars attribute="Control Flow" context="#pop" char="f" char1="i" endRegion="if"/>
        <StringDetect attribute="Control Flow" context="#pop" String="done" endRegion="do"/>
        <Detect2Chars attribute="Control Flow" context="#pop" char="d" char1="o" beginRegion="do"/>
        <!-- handle while/until as a special case -->
        <StringDetect attribute="Control Flow" context="#pop!NotCond" String="while"/>
        <StringDetect attribute="Control Flow" context="#pop!NotCond" String="until"/>
        <!-- handle for as a special case -->
        <StringDetect attribute="Control Flow" context="#pop!For" String="for"/>
        <!-- handle select as a special case -->
        <StringDetect attribute="Control Flow" context="#pop!For" String="select"/>
        <!-- handle case as a special case -->
        <StringDetect attribute="Control Flow" context="#pop!Case" String="case" beginRegion="case"/>
        <!-- handle functions with function keyword before keywords -->
        <StringDetect attribute="Keyword" context="#pop!FunctionDef" String="function"/>
        <StringDetect attribute="Control Flow" context="#pop!Return" String="return"/>
        <!-- not a keyword in this context -->
        <Detect2Chars attribute="Error" context="#pop" char="i" char1="n"/>
        <StringDetect attribute="Error" context="#pop" String="esac"/>
        <!-- handle keywords -->
        <DetectIdentifier attribute="Control Flow" context="#pop"/>
      </context>

      <!-- if ! ..., while ! ... and until ! ... -->
      <context attribute="Normal Text" lineEndContext="#pop" name="NotCond" fallthroughContext="#pop">
        <DetectSpaces attribute="Normal Text" context="#pop!NotCond2"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#pop" name="NotCond2" fallthroughContext="#pop">
        <Detect2Chars attribute="Expression" context="#pop" char="!" char1="&tab;"/>
        <Detect2Chars attribute="Expression" context="#pop" char="!" char1=" "/>
        <LineContinue attribute="Expression" context="#pop" char="!"/>
      </context>

      <context attribute="Normal Text" lineEndContext="#pop" name="For" fallthroughContext="#pop">
        <LineContinue attribute="Escape" context="#stay"/>
        <DetectSpaces attribute="Normal Text" context="#stay"/>
        <DetectIdentifier attribute="Normal Text" context="#pop!ForIn"/>
        <Detect2Chars attribute="Keyword" context="#pop!ForArithmeticExpr" char="(" char1="("/>
      </context>
      <context attribute="Normal Text" lineEndContext="#pop" name="ForIn" fallthroughContext="#pop">
        <DetectSpaces attribute="Normal Text" context="#stay"/>
        <DetectChar attribute="Control" context="#pop" char=";"/>
        <WordDetect attribute="Keyword" context="#pop!CommandArgs" String="in"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#pop" name="ForArithmeticExpr">
        <DetectSpaces attribute="Normal Text" context="#stay"/>
        <DetectChar attribute="Control" context="#stay" char=";"/>
        <Detect2Chars attribute="Keyword" context="#pop" char=")" char1=")"/>
        <IncludeRules context="FindExprDblParen"/>
      </context>

      <context attribute="Normal Text" lineEndContext="#pop" name="AssumeRedirection">
        <!-- handle output redirection -->
        <Detect2Chars attribute="Redirection" context="#pop!WordRedirection" char=">" char1=">"/>
        <Detect2Chars attribute="Redirection" context="#pop!WordRedirection" char=">" char1="|"/>
        <Detect2Chars attribute="Redirection" context="#pop!FdRedirection" char=">" char1="&amp;"/>
        <Detect2Chars attribute="Redirection" context="#pop!ProcessSubst" char=">" char1="("/>
        <DetectChar attribute="Redirection" context="#pop!WordRedirection" char=">"/>
        <StringDetect attribute="Redirection" context="#pop!StringRedirection" String="&lt;&lt;&lt;"/>
        <!-- handle here document -->
        <Detect2Chars context="#pop!HereDoc" char="&lt;" char1="&lt;" lookAhead="1"/>
        <!-- handle input redirection -->
        <Detect2Chars attribute="Redirection" context="#pop!FdRedirection" char="&lt;" char1="&amp;"/>
        <Detect2Chars attribute="Redirection" context="#pop!WordRedirection" char="&lt;" char1=">"/>
        <Detect2Chars attribute="Redirection" context="#pop!ProcessSubst" char="&lt;" char1="("/>
        <DetectChar attribute="Redirection" context="#pop!WordRedirection" char="&lt;"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#pop" name="FdRedirection" fallthroughContext="#pop!FdRedirection2">
        <DetectSpaces attribute="Normal Text"/>
        <DetectChar attribute="Comment" context="#pop!Comment" char="#"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#pop" name="FdRedirection2" fallthroughContext="#pop!WordRedirection2">
        <RegExpr attribute="File Descriptor" context="#pop!CloseFile" String="[0-9]+(?=-?&eoexpr;)"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#pop" name="WordRedirection" fallthroughContext="#pop!WordRedirection2">
        <DetectSpaces attribute="Normal Text"/>
        <DetectChar attribute="Comment" context="#pop!Comment" char="#"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#pop" name="WordRedirection2" fallthroughContext="#pop">
        <AnyChar context="#pop" String="&wordseps;`" lookAhead="1"/>
        <IncludeRules context="FindWord"/>
        <RegExpr attribute="Path" context="PathThenPop" String="&path;"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#pop" name="StringRedirection" fallthroughContext="#pop!StringRedirection2">
        <DetectSpaces attribute="Normal Text"/>
        <DetectChar attribute="Comment" context="#pop!Comment" char="#"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#pop" name="StringRedirection2">
        <AnyChar context="#pop" String="&wordseps;`" lookAhead="1"/>
        <IncludeRules context="FindWord"/>
        <DetectIdentifier attribute="Normal Text"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#pop" name="CloseFile" fallthroughContext="#pop">
        <DetectChar attribute="Keyword" context="#pop" char="-"/>
      </context>

      <!-- HereDoc consumes Here-documents. It is called at the beginning of the "<<" construct. -->
      <context attribute="Normal Text" lineEndContext="#stay" name="HereDoc">
        <RegExpr attribute="Redirection" context="HereDocMLComment" String="^[ &tab;]*&lt;&lt;[ &tab;]*'#([^']+)'$" column="0"/>
        <RegExpr attribute="Redirection" context="HereDocIQ"  String="&lt;&lt;-[ &tab;]*&heredocq;(?=[ &tab;]*$)"/>
        <RegExpr attribute="Redirection" context="HereDocINQ" String="&lt;&lt;-[ &tab;]*([^&wordseps;]+)(?=[ &tab;]*$)"/>
        <RegExpr attribute="Redirection" context="HereDocQ"   String="&lt;&lt;[ &tab;]*&heredocq;(?=[ &tab;]*$)"/>
        <RegExpr attribute="Redirection" context="HereDocNQ"  String="&lt;&lt;[ &tab;]*([^&wordseps;]+)(?=[ &tab;]*$)"/>

        <RegExpr context="HereDocIQCmd"  String="(&lt;&lt;-[ &tab;]*&heredocq;)" lookAhead="1"/>
        <RegExpr context="HereDocINQCmd" String="(&lt;&lt;-[ &tab;]*([^&wordseps;]+))" lookAhead="1"/>
        <RegExpr context="HereDocQCmd"   String="(&lt;&lt;[ &tab;]*&heredocq;)" lookAhead="1"/>
        <RegExpr context="HereDocNQCmd"  String="(&lt;&lt;[ &tab;]*([^&wordseps;]+))" lookAhead="1"/>

        <Detect2Chars attribute="Redirection" context="#pop"  char="&lt;" char1="&lt;"/><!-- always met -->
      </context>

      <context attribute="Normal Text" lineEndContext="#pop" name="HereDocRemainder" fallthroughContext="CommandArg">
        <AnyChar context="BashOneLine" String="&amp;|;`" lookAhead="1"/>
        <IncludeRules context="CommandArgs"/>
      </context>

      <!-- Highlight the builtin `:` (true) and the followed redirection, then fall into `HereDocMLComment` -->
      <context attribute="Comment" lineEndContext="#stay" name="PreHereDocMLComment">
        <DetectChar attribute="Builtin" context="#stay" char=":" column="0"/>
        <RegExpr attribute="Redirection" context="HereDocMLComment" String="&lt;&lt;[ &tab;]*'#([^']+)'$"/>
      </context>

      <context attribute="Comment" lineEndContext="#stay" name="HereDocMLComment" dynamic="true" fallthroughContext="Comment">
        <RegExpr attribute="Redirection" context="#pop#pop" String="^#%1$" column="0" dynamic="true"/>
        <RegExpr attribute="Region Marker" context="RST Documentation" String="^#?\[(=*)\[\.rst:" column="0" beginRegion="RSTDocumentation" />
        <IncludeRules context="Comment"/>
      </context>

      <context attribute="Comment" lineEndContext="#stay" name="RST Documentation" dynamic="true">
        <RegExpr attribute="Redirection" context="#pop#pop#pop" String="^#BLOCK-COMMENT$" column="0"/>
        <RegExpr attribute="Region Marker" context="#pop" String="^#?\]%1\]" dynamic="true" column="0" endRegion="RSTDocumentation" />
        <IncludeRules context="##reStructuredText" />
      </context>

      <context attribute="Here Doc" lineEndContext="#stay" name="HereDocQ" dynamic="true" fallthroughContext="HereDocText">
        <RegExpr attribute="Redirection" context="#pop#pop" String="^%1$" dynamic="true" column="0"/>
      </context>

      <context attribute="Here Doc" lineEndContext="#stay" name="HereDocNQ" dynamic="true" fallthroughContext="HereDocSubstitutions">
        <IncludeRules context="HereDocQ" />
      </context>

      <context attribute="Here Doc" lineEndContext="#stay" name="HereDocIQ" dynamic="true" fallthroughContext="HereDocText">
        <RegExpr attribute="Redirection" context="#pop#pop" String="^\t*%1$" dynamic="true" column="0"/>
      </context>

      <context attribute="Here Doc" lineEndContext="#stay" name="HereDocINQ" dynamic="true" fallthroughContext="HereDocSubstitutions">
        <IncludeRules context="HereDocIQ" />
      </context>

      <context attribute="Here Doc" lineEndContext="#stay" name="HereDocCmd">
        <!-- Only if the redirect is before the command, but as this is too complicated,
             check if the redirect is at the beginning of the line. -->
        <StringDetect attribute="Redirection" context="BashOneLine" String="%1" dynamic="true" firstNonSpace="1"/>
        <StringDetect attribute="Redirection" context="HereDocRemainder" String="%1" dynamic="true"/>
      </context>

      <context attribute="Here Doc" lineEndContext="#stay" name="HereDocQCmd" dynamic="true" fallthroughContext="HereDocText">
        <IncludeRules context="HereDocCmd"/>
        <RegExpr attribute="Redirection" context="#pop#pop" String="^%2$" dynamic="true" column="0"/>
      </context>

      <context attribute="Here Doc" lineEndContext="#stay" name="HereDocNQCmd" dynamic="true" fallthroughContext="HereDocSubstitutions">
        <IncludeRules context="HereDocQCmd"/>
      </context>

      <context attribute="Here Doc" lineEndContext="#stay" name="HereDocIQCmd" dynamic="true" fallthroughContext="HereDocText">
        <IncludeRules context="HereDocCmd"/>
        <RegExpr attribute="Redirection" context="#pop#pop" String="^\t*%2$" dynamic="true" column="0"/>
      </context>

      <context attribute="Here Doc" lineEndContext="#stay" name="HereDocINQCmd" dynamic="true" fallthroughContext="HereDocSubstitutions">
        <IncludeRules context="HereDocIQCmd"/>
      </context>

      <context attribute="Here Doc" lineEndContext="#pop" name="HereDocText">
      </context>

      <context attribute="Here Doc" lineEndContext="#pop" name="HereDocSubstitutions">
        <DetectSpaces attribute="Here Doc"/>
        <DetectIdentifier attribute="Here Doc"/>
        <DetectChar context="HereDocVariables" char="$" lookAhead="1"/>
        <DetectChar attribute="Backquote" context="CommandBackq" char="`"/>
        <DetectChar context="AssumeEscape" char="\" lookAhead="1"/>
      </context>
      <context attribute="Here Doc" lineEndContext="#pop" name="HereDocVariables">
        <IncludeRules context="DispatchSubstVariables"/>
        <IncludeRules context="DispatchVarnameVariables"/>
        <DetectChar attribute="Here Doc" context="#pop" char="$"/>
      </context>

      <!-- VarName consumes spare variable names and assignments -->
      <context attribute="Normal Text" lineEndContext="#pop" name="VarName">
        <StringDetect attribute="Builtin" context="#pop!BuiltinGetopts" String="getopts"/>
        <StringDetect attribute="Builtin" context="#pop!BuiltinLet" String="let"/>
        <DetectIdentifier attribute="Builtin" context="#pop!VarNameArgs"/>
        <AnyChar attribute="Builtin" context="#pop!VarNameArgs" String=".:"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#pop" name="VarNameArgs" fallthroughContext="#pop!CommandArgs">
        <DetectSpaces attribute="Normal Text" context="VarNameArg"/>
        <LineContinue attribute="Escape" context="#stay"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#pop#pop" name="VarNameArg" fallthroughContext="#pop!VarNameArg2">
        <!-- In command arguments, do not allow comments after escaped characters.
             This avoids highlighting comments within paths or other text. Ex: pathtext\ #no\ comment -->
        <DetectChar context="#pop#pop" char="#" lookAhead="1"/>
        <DetectChar attribute="Option" context="#pop!ShortOption" char="-"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#pop" name="VarNameArg2" fallthroughContext="#pop!NormalOption">
        <DetectChar attribute="Variable" context="Subscript" char="["/>
        <DetectChar attribute="Operator" context="Assign" char="="/>
        <DetectChar attribute="Variable" context="AssignArray" char="("/>
        <DetectIdentifier attribute="Variable" context="#stay"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#pop" name="BuiltinGetopts" fallthroughContext="#pop!CommandArgs">
        <DetectSpaces attribute="Normal Text" context="#pop!BuiltinGetoptsOpt"/>
        <LineContinue attribute="Escape" context="#stay"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#pop#pop" name="BuiltinGetoptsOpt" fallthroughContext="#pop!BuiltinGetoptsOpt2">
        <DetectChar context="#pop#pop" char="#" lookAhead="1"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#pop" name="BuiltinGetoptsOpt2" fallthroughContext="#pop!NormalOption">
        <DetectChar attribute="Operator" context="#stay" char=":"/>
        <DetectIdentifier attribute="Normal Text" context="#stay" />
        <DetectSpaces attribute="Normal Text" context="#pop!BuiltinGetoptsVar"/>
        <AnyChar context="#pop" String="&wordseps;`" lookAhead="1"/>
        <IncludeRules context="FindWord"/>
        <DetectChar context="NormalMaybeBraceExpansion" char="{" lookAhead="1"/>
        <AnyChar attribute="Normal Text" context="#stay" String="/%.0123456789"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#pop" name="BuiltinGetoptsVar" fallthroughContext="#pop!CommandArgs">
        <DetectIdentifier attribute="Variable" context="#pop!CommandArgs"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#pop" name="BuiltinLet" fallthroughContext="#pop!CommandArgs">
        <DetectSpaces attribute="Normal Text" context="#pop!BuiltinLetArgs"/>
        <LineContinue attribute="Escape" context="#stay"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#pop" name="BuiltinLetArgs" fallthroughContext="BuiltinLetArg">
        <AnyChar context="BuiltinLetArgsNumber" String="0123456789" lookAhead="1"/>
        <IncludeRules context="CommandArgs"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#pop" name="BuiltinLetArgsNumber" fallthroughContext="#pop!BuiltinLetArg">
        <IncludeRules context="FindRedirection"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#pop#pop" name="BuiltinLetArg" fallthroughContext="#pop!BuiltinLetExpr">
        <DetectChar context="#pop#pop" char="#" lookAhead="1"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#pop" name="BuiltinLetExpr" fallthroughContext="#pop!NormalOption">
        <DetectIdentifier attribute="Variable" context="#stay" />
        <AnyChar context="#pop" String="&wordseps;`" lookAhead="1"/>
        <AnyChar attribute="Operator" context="#stay" String="+-/%=^:"/>
        <AnyChar context="Number" String="0123456789" lookAhead="1"/>
        <DetectChar attribute="Parameter Expansion Operator" context="Subscript" char="["/>
        <IncludeRules context="FindWord"/>
        <DetectChar attribute="Error" context="#stay" char="#"/>
        <DetectChar context="NormalMaybeBraceExpansion" char="{" lookAhead="1"/>
      </context>

      <!-- ProcessSubst handles <(command) and >(command) -->
      <context attribute="Normal Text" lineEndContext="#stay" name="ProcessSubst" fallthroughContext="Command">
        <DetectChar attribute="Redirection" context="#pop" char=")"/>
        <IncludeRules context="Start"/>
      </context>

      <!-- StringSQ consumes anything till ' -->
      <context attribute="String SingleQ" lineEndContext="#stay" name="StringSQ">
        <DetectSpaces attribute="String SingleQ"/>
        <DetectIdentifier attribute="String SingleQ"/>
        <DetectChar attribute="String SingleQ" context="#pop" char="'"/>
      </context>

      <!-- StringDQ consumes anything till ", substitutes vars and expressions -->
      <context attribute="String DoubleQ" lineEndContext="#stay" name="StringDQ">
        <DetectSpaces attribute="String DoubleQ"/>
        <DetectIdentifier attribute="String DoubleQ"/>
        <DetectChar attribute="String DoubleQ" context="#pop" char="&quot;"/>
        <DetectChar context="StringDQEscape" char="\" lookAhead="1"/>
        <DetectChar context="StringDQDispatchVariables" char="$" lookAhead="1"/>
        <DetectChar attribute="Backquote" context="RegularBackq" char="`"/>
      </context>
      <context attribute="String DoubleQ" lineEndContext="#stay" name="StringDQDispatchVariables">
        <IncludeRules context="DispatchSubstVariables"/>
        <IncludeRules context="DispatchVarnameVariables"/>
        <DetectChar attribute="String DoubleQ" context="#pop" char="$"/>
      </context>
      <context attribute="String DoubleQ" lineEndContext="#pop" name="StringDQEscape">
        <Detect2Chars attribute="String Escape" context="#pop" char="\" char1="&quot;"/>
        <Detect2Chars attribute="String Escape" context="#pop" char="\" char1="\"/>
        <Detect2Chars attribute="String Escape" context="#pop" char="\" char1="`"/>
        <Detect2Chars attribute="String Escape" context="#pop" char="\" char1="$"/>
        <LineContinue attribute="String Escape" context="#pop"/>
        <DetectChar attribute="String DoubleQ" context="#pop" char="\"/>
      </context>

      <!-- RegularBackq consumes anything till ` -->
      <context attribute="Normal Text" lineEndContext="#stay" name="RegularBackq" fallthroughContext="Command">
        <DetectChar attribute="Backquote" context="#pop" char="`"/>
        <DetectChar attribute="Comment" context="CommentBackq" char="#"/>
        <IncludeRules context="Start"/>
      </context>

      <!-- StringEsc eats till ', but escaping many characters in $'...' -->
      <context attribute="String SingleQ" lineEndContext="#stay" name="StringEsc">
        <DetectSpaces attribute="String SingleQ"/>
        <DetectIdentifier attribute="String SingleQ"/>
        <DetectChar attribute="String SingleQ" context="#pop" char="'"/>
        <RegExpr attribute="String Escape" context="#stay" String="\\(?:[abeEfnrtv\\'&quot;?]|[0-7]{1,3}|x[A-Fa-f0-9]{1,2}|u[A-Fa-f0-9]{1,4}|U[A-Fa-f0-9]{1,8}|c.)"/>
      </context>

      <context attribute="Normal Text" lineEndContext="#stay" name="FindWord">
        <IncludeRules context="FindStrings"/>
        <DetectChar context="RegularVariable" char="$" lookAhead="1"/>
        <DetectChar attribute="Backquote" context="RegularBackq" char="`"/>
        <DetectChar context="AssumeEscape" char="\" lookAhead="1"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#pop" name="RegularVariable">
        <IncludeRules context="DispatchVariables"/>
        <DetectChar attribute="Normal Text" context="#pop" char="$"/>
      </context>

      <context attribute="Normal Text" lineEndContext="#pop" name="FindStrings">
        <DetectChar attribute="String SingleQ" context="StringSQ" char="'"/>
        <DetectChar attribute="String DoubleQ" context="StringDQ" char="&quot;"/>
      </context>

      <!-- SubstCommand is called after a $( is encountered -->
      <context attribute="Normal Text" lineEndContext="#stay" name="SubstCommand" fallthroughContext="Command">
        <DetectChar attribute="Parameter Expansion" context="#pop" char=")" endRegion="subshell"/>
        <IncludeRules context="Start"/>
      </context>

      <!-- VarBraceStart is called as soon as ${ is encoutered -->
      <context attribute="Variable" lineEndContext="SubstBraceCommand" name="VarBraceStart" fallthroughContext="#pop!VarBrace">
        <!-- '${!}' as process ID variable, not a Parameter Expansion -->
        <StringDetect context="#pop!VarBrace" String="!}" lookAhead="1"/>
        <DetectChar attribute="Parameter Expansion Operator" context="#pop!VarBracePrefix" char="!"/>
        <DetectChar attribute="Parameter Expansion Operator" context="#pop!VarBrace" char="#"/>
        <!-- Bash-5.3: ${ cmd; } -->
        <DetectSpaces attribute="Normal Text" context="SubstBraceCommand"/>
        <!-- Bash-5.3: ${|cmd;} -->
        <DetectChar attribute="Control" context="SubstBraceCommand" char="|"/>
      </context>

      <!-- SubstBraceCommand is called after a '${ ' are '${|' are encountered -->
      <context attribute="Normal Text" lineEndContext="#stay" name="SubstBraceCommand" fallthroughContext="Command">
        <DetectChar attribute="Parameter Expansion" context="#pop" char="}"/>
        <IncludeRules context="Start"/>
      </context>

      <!-- VarBracePrefix called as soon as ${! is encoutered -->
      <context attribute="Variable" lineEndContext="#pop" name="VarBracePrefix">
        <DetectIdentifier attribute="Variable" context="#pop!VarBracePrefixSuffix"/>
        <Int attribute="Variable" context="#pop!VarBracePrefixSuffix"/>
        <AnyChar attribute="Parameter Expansion Operator" context="#pop!VarBracePrefixSharp" String="@*#"/>
        <DetectChar attribute="Parameter Expansion" context="#pop" char="}"/>
      </context>
      <context attribute="Variable" lineEndContext="#pop" name="VarBracePrefixSuffix" fallthroughContext="#pop!VarError">
        <DetectChar attribute="Parameter Expansion" context="#pop" char="}"/>
        <AnyChar attribute="Parameter Expansion Operator" context="#stay" String="@*"/>
        <StringDetect attribute="Parameter Expansion Operator" context="#stay" String="[@]"/>
        <StringDetect attribute="Parameter Expansion Operator" context="#stay" String="[*]"/>
      </context>
      <context attribute="Variable" lineEndContext="#pop" name="VarBracePrefixSharp" fallthroughContext="#pop!VarError">
        <DetectChar attribute="Parameter Expansion" context="#pop" char="}"/>
        <DetectChar attribute="Parameter Expansion Operator" char="#"/>
      </context>

      <!-- VarBrace is called as soon as ${ or ${# are encoutered -->
      <context attribute="Variable" lineEndContext="#stay" name="VarBrace" fallthroughContext="#pop!VarError">
        <DetectChar attribute="Parameter Expansion" context="#pop" char="}"/>
        <DetectIdentifier attribute="Variable" context="#pop!CheckVarAlt"/>
        <AnyChar attribute="Variable" context="#pop!CheckVarAlt" String="*@?$!-"/>
        <Int attribute="Variable" context="#pop!CheckVarAlt" additionalDeliminator=":#%^,/@{}"/>
      </context>
      <context attribute="Error" lineEndContext="#stay" name="VarError">
        <DetectChar attribute="Parameter Expansion" context="#pop" char="}"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#stay" name="CheckVarAlt" fallthroughContext="#pop!VarError">
        <DetectChar attribute="Parameter Expansion" context="#pop" char="}"/>
        <StringDetect attribute="Parameter Expansion Operator" context="#stay" String="[@]"/>
        <StringDetect attribute="Parameter Expansion Operator" context="#stay" String="[*]"/>
        <DetectChar attribute="Parameter Expansion Operator" context="Subscript" char="["/>
        <Detect2Chars attribute="Parameter Expansion Operator" context="#pop!AlternateValue" char=":" char1="-"/>
        <Detect2Chars attribute="Parameter Expansion Operator" context="#pop!AlternateValue" char=":" char1="="/>
        <Detect2Chars attribute="Parameter Expansion Operator" context="#pop!AlternateValue" char=":" char1="?"/>
        <Detect2Chars attribute="Parameter Expansion Operator" context="#pop!AlternateValue" char=":" char1="+"/>
        <Detect2Chars attribute="Parameter Expansion Operator" context="#pop!AlternateValue" char="#" char1="#"/>
        <Detect2Chars attribute="Parameter Expansion Operator" context="#pop!AlternateValue" char="%" char1="%"/>
        <Detect2Chars attribute="Parameter Expansion Operator" context="#pop!AlternatePatternValue" char="^" char1="^"/>
        <Detect2Chars attribute="Parameter Expansion Operator" context="#pop!AlternatePatternValue" char="," char1=","/>
        <DetectChar attribute="Parameter Expansion Operator" context="#pop!VarSub" char=":"/>
        <DetectChar attribute="Parameter Expansion Operator" context="#pop!VarSubst" char="/"/>
        <AnyChar attribute="Parameter Expansion Operator" context="#pop!AlternateValue" String="-+=?#%"/>
        <AnyChar attribute="Parameter Expansion Operator" context="#pop!AlternatePatternValue" String="^,"/>
        <DetectChar attribute="Parameter Expansion Operator" context="#pop!VarTransformation" char="@"/>
      </context>

      <!-- called as soon as ${xxx: is encoutered -->
      <context attribute="Normal Text" lineEndContext="#stay" name="VarSub">
        <DetectChar attribute="Parameter Expansion" context="#pop" char="}"/>
        <!-- <Int> doesn't match :3 because : is a weakDeliminator -->
        <AnyChar attribute="Decimal" String="0123456789"/>
        <DetectChar attribute="Parameter Expansion Operator" context="#stay" char=":"/>
        <DetectChar context="VarVariables" char="$" lookAhead="1"/>
        <IncludeRules context="FindStrings"/>
        <DetectChar attribute="Backquote" context="RegularBackq" char="`"/>
        <DetectChar context="AssumeEscape" char="\" lookAhead="1"/>
      </context>
      <context attribute="Command" lineEndContext="#pop" name="VarVariables">
        <IncludeRules context="DispatchVariables"/>
        <DetectChar attribute="Error" context="#pop" char="$"/>
      </context>

      <!-- called as soon as ${xxx:- ${xxx:= ${xxx:? ${xxx:+ ${xxx# ${xxx% and ${xxx are encoutered -->
      <context attribute="Normal Text" lineEndContext="#stay" name="AlternateValue">
        <DetectChar attribute="Parameter Expansion" context="#pop" char="}"/>
        <IncludeRules context="FindWord"/>
        <IncludeRules context="FindPathThenPopInAlternateValue"/>
        <DetectIdentifier attribute="Normal Text"/>
      </context>

      <!-- called as soon as ${xxx^ are ${xxx, are encoutered -->
      <context attribute="Pattern" lineEndContext="#stay" name="AlternatePatternValue">
        <DetectChar attribute="Parameter Expansion" context="#pop" char="}"/>
        <IncludeRules context="FindWord"/>
        <IncludeRules context="FindPattern"/>
        <DetectIdentifier attribute="Pattern"/>
      </context>

      <!-- called as soon as ${xxx/ is encoutered -->
      <context attribute="Normal Text" lineEndContext="#stay" name="VarSubst" fallthroughContext="#pop!VarSubstPat">
        <AnyChar attribute="Parameter Expansion Operator" context="#pop!VarSubstPat" String="/#%"/>
      </context>
      <context attribute="Pattern" lineEndContext="#stay" name="VarSubstPat">
        <DetectChar attribute="Parameter Expansion Operator" context="#pop!AlternateValue" char="/"/>
        <IncludeRules context="AlternatePatternValue"/>
      </context>

      <!-- called as soon as ${xxx@ is encoutered -->
      <context attribute="Normal Text" lineEndContext="#stay" name="VarTransformation" fallthroughContext="#pop!VarError">
        <DetectChar attribute="Parameter Expansion" context="#pop" char="}"/>
        <AnyChar attribute="Parameter Expansion" context="#stay" String="UuLQEPAKak"/>
      </context>

      <context attribute="Escape" lineEndContext="#pop" name="BraceExpansion">
        <DetectChar attribute="Escape" context="#pop!BraceExpansion2" char="{"/>
      </context>
      <context attribute="Escape" lineEndContext="#pop" name="BraceExpansion2">
        <DetectChar attribute="Operator" context="#stay" char=","/>
        <DetectChar attribute="Escape" context="#pop" char="}"/>
        <DetectChar context="EscapeMaybeBraceExpansion" char="{" lookAhead="1"/>
        <DetectChar context="AssumeEscape" char="\" lookAhead="1"/>
        <DetectChar attribute="Backquote" context="CommandBackq" char="`"/>
        <DetectChar context="BraceExpansionVariables" char="$" lookAhead="1"/>
        <IncludeRules context="FindStrings"/>
        <IncludeRules context="FindPattern"/>
        <DetectIdentifier attribute="Escape"/>
      </context>
      <context attribute="Escape" lineEndContext="#pop" name="EscapeMaybeBraceExpansion">
        <IncludeRules context="DispatchBraceExpansion"/>
        <DetectChar attribute="Escape" context="#pop!BraceExpansion2" char="{"/>
      </context>
      <context attribute="Escape" lineEndContext="#pop" name="BraceExpansionVariables">
        <IncludeRules context="DispatchVariables"/>
        <DetectChar attribute="Escape" context="#pop" char="$"/>
      </context>

      <context attribute="Normal Text" lineEndContext="#pop" name="SequenceExpression">
        <AnyChar attribute="Decimal" context="#stay" String="0123456789-+"/>
        <Detect2Chars attribute="Escape" context="#stay" char="." char1="."/>
        <DetectChar attribute="Escape" context="#pop" char="}"/>
      </context>

<!-- ====== These are the contexts that can be branched to ======= -->

      <context attribute="Normal Text" lineEndContext="#stay" name="ExprDblParenOrSubShell">
        <RegExpr attribute="Keyword" context="#pop!SubShell" String="\((?=&arithmetic_as_subshell;)|" beginRegion="subshell"/>
        <Detect2Chars attribute="Keyword" context="#pop!ExprDblParen" char="(" char1="(" beginRegion="expression"/>
      </context>
      <!-- ExprDblParen consumes an expression started in command mode till )) -->
      <context attribute="Normal Text" lineEndContext="#stay" name="ExprDblParen">
        <DetectSpaces attribute="Normal Text" context="#stay"/>
        <Detect2Chars attribute="Keyword" context="#pop" char=")" char1=")" endRegion="expression"/>
        <IncludeRules context="FindExprDblParen"/>
        <!-- ((cmd
              ) # jump to SubShell context -->
        <DetectChar attribute="Keyword" context="#pop!SubShell" char=")" endRegion="expression" beginRegion="subshell"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#stay" name="FindExprDblParen">
        <Detect2Chars attribute="Control" context="#stay" char="&amp;" char1="&amp;"/>
        <Detect2Chars attribute="Control" context="#stay" char="|" char1="|"/>
        <AnyChar attribute="Operator" context="#stay" String="+-!~*/%&lt;>=&amp;^|?:"/>
        <AnyChar context="Number" String="0123456789" lookAhead="1"/>
        <DetectChar attribute="Control" context="#stay" char=","/>
        <DetectChar attribute="Normal Text" context="ExprSubDblParen" char="("/>
        <DetectChar attribute="Parameter Expansion Operator" context="Subscript" char="["/>
        <IncludeRules context="FindWord"/>
        <DetectChar attribute="Error" context="#stay" char="#"/>
        <DetectChar context="MaybeArithmeticBrace" char="{" lookAhead="1"/>
        <DetectIdentifier attribute="Variable" context="#stay"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#stay" name="ExprSubDblParen">
        <DetectSpaces attribute="Normal Text" context="#stay"/>
        <DetectChar attribute="Normal Text" context="#pop" char=")"/>
        <IncludeRules context="FindExprDblParen"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#pop" name="MaybeArithmeticBrace">
        <IncludeRules context="DispatchBraceExpansion"/>
        <DetectChar attribute="Error" context="#pop" char="{"/>
      </context>

      <context attribute="Decimal" lineEndContext="#pop" name="Number">
        <HlCHex attribute="Hex" context="#pop" additionalDeliminator="&weakDeliminatorSymbols;"/>
        <HlCOct attribute="Octal" context="#pop!NumberError" additionalDeliminator="&weakDeliminatorSymbols;"/>
        <RegExpr attribute="Base" context="#pop!BaseN" String="[1-9][0-9]*#"/>
        <DetectChar attribute="Decimal" context="#pop!NumberError" char="0"/>
        <Int attribute="Decimal" context="#pop" additionalDeliminator="&weakDeliminatorSymbols;"/>
      </context>
      <context attribute="BaseN" lineEndContext="#pop" name="BaseN" fallthroughContext="#pop">
        <RegExpr attribute="BaseN" context="#pop" String="[0-9a-zA-Z@_]+"/>
      </context>
      <context attribute="Error" lineEndContext="#pop" name="NumberError" fallthroughContext="#pop">
        <Int attribute="Error" context="#pop" additionalDeliminator="0123456789"/>
      </context>

      <context attribute="Normal Text" lineEndContext="#stay" name="ExprDblParenSubstOrSubstCommand">
        <RegExpr attribute="Parameter Expansion" context="#pop!SubstCommand" String="\$\((?=&arithmetic_as_subshell;)|" beginRegion="subshell"/>
        <StringDetect attribute="Parameter Expansion" context="#pop!ExprDblParenSubst" String="$((" beginRegion="expression"/>
      </context>
      <!-- ExprDblParenSubst like ExprDblParen but matches )) as Variable -->
      <context attribute="Normal Text" lineEndContext="#stay" name="ExprDblParenSubst">
        <DetectSpaces attribute="Normal Text" context="#stay"/>
        <Detect2Chars attribute="Parameter Expansion" context="#pop" char=")" char1=")" endRegion="expression"/>
        <IncludeRules context="FindExprDblParen"/>
        <!-- $((cmd
              ) # jump to SubstCommand context -->
        <DetectChar attribute="Parameter Expansion" context="#pop!SubstCommand" char=")" endRegion="expression" beginRegion="subshell"/>
      </context>

      <!-- ExprBracket consumes an expression till ] -->
      <context attribute="Normal Text" lineEndContext="#stay" name="ExprBracket" fallthroughContext="#pop!ExprBracketNot">
        <DetectSpaces attribute="Normal Text" context="#stay"/>
        <IncludeRules context="FindExprBracketEnd"/>
      </context>

      <context attribute="Normal Text" lineEndContext="#stay" name="ExprBracketNot" fallthroughContext="#pop!ExprBracketParam1">
        <DetectSpaces attribute="Normal Text" context="#pop!ExprBracketParam1"/>
        <Detect2Chars attribute="Expression" context="ExprBracketTestMaybeNot" char="!" char1=" " lookAhead="1"/>
        <Detect2Chars attribute="Expression" context="ExprBracketTestMaybeNot" char="!" char1="&tab;" lookAhead="1"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#pop" name="ExprBracketTestMaybeNot">
        <DetectChar attribute="Expression" context="#pop" char="!"/>
      </context>

      <context attribute="Normal Text" lineEndContext="#stay" name="ExprBracketParam1" fallthroughContext="ExprBracketValue">
        <DetectSpaces attribute="Normal Text" context="#pop!ExprBracketParam2"/>
        <DetectChar context="TestMaybeUnary" char="-" lookAhead="1"/>
        <IncludeRules context="FindExprBracketEnd"/>
      </context>

      <context attribute="Normal Text" lineEndContext="#pop" name="ExprBracketValue">
        <AnyChar attribute="Error" context="#stay" String="&symbolseps;"/>
        <AnyChar context="#pop" String=" &tab;" lookAhead="1"/>
        <IncludeRules context="FindWord"/>
        <DetectChar context="NormalMaybeBraceExpansion" char="{" lookAhead="1"/>
        <IncludeRules context="FindNormalText"/>
      </context>

      <context attribute="Normal Text" lineEndContext="#stay" name="ExprBracketParam2" fallthroughContext="#pop!ExprBracketParam2_Value">
        <LineContinue attribute="Escape" context="SkipSpaces"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#stay" name="ExprBracketParam2_Value" fallthroughContext="ExprBracketValue">
        <DetectSpaces attribute="Normal Text" context="#pop!ExprBracketParam3"/>
        <AnyChar context="TestMaybeBinary" String="-=!" lookAhead="1"/>
        <IncludeRules context="FindExprBracketEnd"/>
      </context>

      <context attribute="Normal Text" lineEndContext="ExprBracketFinal" name="ExprBracketParam3" fallthroughContext="#pop!ExprBracketParam3_Value">
        <LineContinue attribute="Escape" context="SkipSpaces"/>
      </context>
      <context attribute="Normal Text" lineEndContext="ExprBracketFinal" name="ExprBracketParam3_Value" fallthroughContext="ExprBracketValue">
        <DetectSpaces attribute="Normal Text" context="#pop!ExprBracketFinal"/>
        <IncludeRules context="FindExprBracketEnd"/>
      </context>

      <context attribute="Normal Text" lineEndContext="#stay" name="ExprBracketFinal" fallthroughContext="ExprBracketValue">
        <DetectSpaces attribute="Normal Text" context="#stay"/>
        <IncludeRules context="FindExprBracketEnd"/>
        <RegExpr attribute="Expression" context="#pop!ExprBracket" String="-[ao]&eos;"/>
        <RegExpr attribute="Error" context="#pop" String="(?:[^] &tab;]++|\][^ &tab;])++" endRegion="expression"/>
      </context>

      <context attribute="Normal Text" lineEndContext="#stay" name="FindExprBracketEnd">
        <LineContinue attribute="Escape" context="#stay"/>
        <RegExpr attribute="Builtin" context="#pop" String="\](?=($|[ &tab;;|&amp;&lt;>)]))" endRegion="expression"/>
      </context>

      <context attribute="Normal Text" lineEndContext="#pop" name="TestMaybeUnary" fallthroughContext="#pop!ExprBracketValue">
        <RegExpr attribute="Expression" context="#pop#pop!ExprBracketParam2" String="&unary_operators;"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#pop" name="TestMaybeBinary" fallthroughContext="#pop!ExprBracketValue">
        <RegExpr attribute="Expression" context="#pop" String="&binary_operators;"/>
      </context>

      <context attribute="Normal Text" lineEndContext="#pop" name="SkipSpaces" fallthroughContext="#pop">
        <DetectSpaces context="#pop"/>
      </context>


      <!-- ExprDblBracket consumes an expression till ]] in [[ ... ]] -->
      <context attribute="Normal Text" lineEndContext="#stay" name="ExprDblBracket" fallthroughContext="#pop!ExprDblBracketNot">
        <DetectSpaces attribute="Normal Text" context="#stay"/>
        <DetectChar attribute="Comment" context="Comment" char="#"/>
        <IncludeRules context="FindExprDblBracketEnd"/>
      </context>

      <context attribute="Normal Text" lineEndContext="#stay" name="ExprDblBracketNot" fallthroughContext="#pop!ExprDblBracketParam1">
        <DetectSpaces attribute="Normal Text" context="#pop!ExprDblBracketParam1"/>
        <DetectChar context="ExprDblBracketTestMaybeNot" char="!" lookAhead="1"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#pop" name="ExprDblBracketTestMaybeNot" fallthroughContext="#pop#pop!ExprDblBracketParam1">
        <RegExpr attribute="Expression" context="#pop" String="!(?=$|[ &tab;(])"/>
      </context>

      <context attribute="Normal Text" lineEndContext="#stay" name="ExprDblBracketParam1" fallthroughContext="ExprDblBracketValueText">
        <DetectSpaces attribute="Normal Text" context="#pop!ExprDblBracketParam2"/>
        <DetectChar context="TestMaybeUnary2" char="-" lookAhead="1"/>
        <AnyChar attribute="Expression" context="#pop!ExprDblBracketParam3Spe" String="&lt;>"/>
        <IncludeRules context="FindExprDblBracketEnd"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#pop" name="TestMaybeUnary2" fallthroughContext="#pop!ExprDblBracketValueText">
        <RegExpr attribute="Expression" context="#pop!ExprDblBracketUnary" String="&unary_operators;(?!\s+(?:=~|&binary_operators;))"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#pop" name="ExprDblBracketUnary">
        <DetectSpaces attribute="Normal Text" context="#pop!ExprDblBracketValueText"/>
      </context>

      <context attribute="Normal Text" lineEndContext="#pop" name="ExprDblBracketValueText" fallthroughContext="#pop!ExprDblBracketValueText2">
        <Detect2Chars context="#pop!ExprDblBracketValueTextMaybeEnd" char="]" char1="]" lookAhead="1"/>
        <DetectChar attribute="Error" context="#pop!Comment" char="#"/>
        <IncludeRules context="FindExprDblBracketValueTextPath"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#pop" name="FindExprDblBracketValueTextPath">
        <RegExpr context="#pop!ExprDblBracketValueTextPath" String="&path_with_sep;|" lookAhead="1"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#pop" name="ExprDblBracketValueTextMaybeEnd">
        <RegExpr attribute="Keyword" context="#pop#pop" String="&dblbracket_close;" endRegion="expression"/>
        <IncludeRules context="FindExprDblBracketValueTextPath"/>
        <Detect2Chars context="#pop!ExprDblBracketValueText2" char="]" char1="]" lookAhead="1"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#pop" name="ExprDblBracketValueText2">
        <DetectIdentifier/>
        <AnyChar String="*?+!@~^:%+-/,"/>
        <IncludeRules context="ExprDblBracketValueCommon"/>
      </context>
      <context attribute="Path" lineEndContext="#pop" name="ExprDblBracketValueTextPath">
        <IncludeRules context="ExprDblBracketValueText2"/>
      </context>

      <context attribute="Normal Text" lineEndContext="#pop" name="ExprDblBracketValuePattern" fallthroughContext="#pop!ExprDblBracketValuePattern2">
        <RegExpr context="PathThenPop" String="&path_with_sep;|" lookAhead="1"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#pop" name="ExprDblBracketValuePattern2">
        <DetectIdentifier attribute="Normal Text"/>
        <IncludeRules context="ExprDblBracketValueCommon"/>
        <IncludeRules context="FindExprDblBracketValueExtGlob"/>
        <AnyChar attribute="Glob" String="?*"/>
      </context>
      <context attribute="Glob" lineEndContext="#stay" name="FindExprDblBracketValueExtGlob">
        <Detect2Chars attribute="Glob" context="ExprDblBracketValueExtGlob" char="?" char1="("/>
        <Detect2Chars attribute="Glob" context="ExprDblBracketValueExtGlob" char="*" char1="("/>
        <Detect2Chars attribute="Glob" context="ExprDblBracketValueExtGlob" char="+" char1="("/>
        <Detect2Chars attribute="Glob" context="ExprDblBracketValueExtGlob" char="@" char1="("/>
        <Detect2Chars attribute="Glob" context="ExprDblBracketValueExtGlob" char="!" char1="("/>
        <DetectChar context="ExprDblBracketValueMaybeGlobAny" char="[" lookAhead="1"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#stay" name="ExprDblBracketValueMaybeGlobAny" fallthroughContext="#pop">
        <IncludeRules context="FindGlobAny"/>
        <DetectChar attribute="Normal Text" context="#pop" char="["/>
      </context>
      <context attribute="Normal Text" lineEndContext="#pop#pop" name="ExprDblBracketValueExtGlob">
        <DetectIdentifier attribute="Normal Text"/>
        <DetectChar attribute="Glob" context="#pop" char=")"/>
        <DetectChar attribute="Normal Text" context="ExprDblBracketValueExtGlobNormal" char="("/>
        <IncludeRules context="FindExprDblBracketValueExtGlob"/>
        <AnyChar attribute="Glob" String="|?*"/>
        <IncludeRules context="FindWord"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#pop#pop" name="ExprDblBracketValueExtGlobNormal">
        <DetectIdentifier attribute="Normal Text"/>
        <DetectChar attribute="Normal Text" context="#pop" char=")"/>
        <DetectChar attribute="Normal Text" context="ExprDblBracketValueExtGlobNormal" char="("/>
        <IncludeRules context="FindExprDblBracketValueExtGlob"/>
        <AnyChar attribute="Glob" String="?*"/>
        <IncludeRules context="FindWord"/>
      </context>

      <context attribute="Normal Text" lineEndContext="#pop" name="ExprDblBracketValueCommon">
        <Detect2Chars context="ExprDblBracketDblParentOrSubValue" char="(" char1="(" lookAhead="1"/>
        <DetectChar context="ExprDblBracketSubValue" char="(" lookAhead="1"/>
        <DetectChar attribute="Operator" context="#pop#pop" char=")"/>
        <Detect2Chars attribute="Control" context="#pop#pop!ExprDblBracket" char="&amp;" char1="&amp;"/>
        <Detect2Chars attribute="Control" context="#pop#pop!ExprDblBracket" char="|" char1="|"/>
        <AnyChar attribute="Error" context="#stay" String="|&amp;;"/>
        <AnyChar context="#pop" String=" &tab;&lt;>" lookAhead="1"/>
        <IncludeRules context="FindWord"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#pop" name="ExprDblBracketSubValue" fallthroughContext="#pop">
        <DetectChar attribute="Operator" context="ExprDblBracketNot" char="("/>
        <Detect2Chars context="#pop#pop" char="]" char1="]" lookAhead="1"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#pop" name="ExprDblBracketDblParentOrSubValue">
        <RegExpr context="#pop!ExprDblBracketSubValue" String="\((?=&arithmetic_as_subshell;)|" lookAhead="1"/>
        <Detect2Chars attribute="Keyword" context="#pop!ExprDblBracketExprDblParen" char="(" char1="(" beginRegion="expression"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#stay" name="ExprDblBracketExprDblParen">
        <DetectSpaces attribute="Normal Text" context="#stay"/>
        <Detect2Chars attribute="Keyword" context="#pop" char=")" char1=")" endRegion="expression"/>
        <IncludeRules context="FindExprDblParen"/>
        <!-- ((cmd
              ) # jump to ExprDblBracketValuePattern context -->
        <DetectChar attribute="Operator" context="ExprDblBracketValuePattern" char=")" endRegion="expression" beginRegion="subshell"/>
      </context>

      <context attribute="Normal Text" lineEndContext="#stay" name="ExprDblBracketParam2" fallthroughContext="#pop!ExprDblBracketParam2_Value">
        <LineContinue attribute="Escape" context="SkipSpaces"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#stay" name="ExprDblBracketParam2_Value" fallthroughContext="ExprDblBracketValuePattern">
        <DetectSpaces attribute="Normal Text" context="#pop!ExprDblBracketParam3"/>
        <AnyChar context="TestMaybeBinary2" String="-=!" lookAhead="1"/>
        <AnyChar attribute="Expression" context="#pop!ExprDblBracketParam3Spe" String="&lt;>"/>
        <IncludeRules context="FindExprDblBracketEnd"/>
        <DetectChar attribute="Comment" context="Comment" char="#"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#pop" name="TestMaybeBinary2" fallthroughContext="#pop!ExprDblBracketValuePattern">
        <IncludeRules context="TestMaybeBinary"/>
        <RegExpr attribute="Expression" context="#pop!ExprDblBracketRegex" String="=~(?=[ &tab;(])"/>
      </context>

      <context attribute="Normal Text" lineEndContext="#stay" name="ExprDblBracketParam3Spe" fallthroughContext="#pop!ExprDblBracketParam3">
        <DetectSpaces attribute="Normal Text" context="#pop!ExprDblBracketParam3"/>
      </context>

      <context attribute="Normal Text" lineEndContext="#stay" name="ExprDblBracketParam3" fallthroughContext="#pop!ExprDblBracketParam3_Value">
        <LineContinue attribute="Escape" context="SkipSpaces"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#stay" name="ExprDblBracketParam3_Value" fallthroughContext="ExprDblBracketValuePattern">
        <DetectSpaces attribute="Normal Text" context="#pop!ExprDblBracketFinal"/>
        <IncludeRules context="FindExprDblBracketEnd"/>
        <AnyChar attribute="Error" context="#stay" String="&lt;>"/>
        <DetectChar attribute="Comment" context="Comment" char="#"/>
      </context>

      <context attribute="Normal Text" lineEndContext="#stay" name="ExprDblBracketFinal" fallthroughContext="ExprDblBracketValuePattern">
        <DetectSpaces attribute="Normal Text" context="#stay"/>
        <IncludeRules context="FindExprDblBracketEnd"/>
        <DetectChar attribute="Comment" context="Comment" char="#"/>
        <DetectChar attribute="Operator" context="#pop" char=")"/>
        <RegExpr attribute="Error" context="#pop" String="(?:[^] &tab;]++|\](?:[^]]|\][^ &tab;]))++" endRegion="expression"/>
      </context>

      <context attribute="Normal Text" lineEndContext="#stay" name="FindExprDblBracketEnd">
        <LineContinue attribute="Escape" context="#stay"/>
        <Detect2Chars attribute="Control" context="#pop!ExprDblBracket" char="&amp;" char1="&amp;"/>
        <Detect2Chars attribute="Control" context="#pop!ExprDblBracket" char="|" char1="|"/>
        <RegExpr attribute="Keyword" context="#pop" String="&dblbracket_close;" endRegion="expression"/>
      </context>

      <context attribute="Normal Text" lineEndContext="#stay" name="ExprDblBracketRegex" fallthroughContext="#pop!ExprDblBracketRegexCheck">
        <DetectSpaces attribute="Normal Text" context="#pop!ExprDblBracketRegexCheck"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#pop" name="ExprDblBracketRegexCheck" fallthroughContext="#pop#pop!Regex">
        <DetectChar attribute="Error" context="Comment" char="#"/>
      </context>
      <context attribute="Pattern" lineEndContext="#stay" name="Regex">
        <DetectIdentifier attribute="Pattern"/>
        <DetectSpaces attribute="Normal Text" context="#pop!ExprDblBracketFinal"/>
        <DetectChar attribute="Operator" context="#pop" char=")"/>
        <Detect2Chars attribute="Operator" context="RegexChar" char="[" char1="^"/>
        <DetectChar attribute="Operator" context="RegexChar" char="["/>
        <IncludeRules context="FindRegex"/>
      </context>
      <context attribute="Pattern" lineEndContext="#stay" name="ExprDblBracketSubRegex">
        <DetectIdentifier attribute="Pattern"/>
        <DetectSpaces attribute="Pattern" context="#stay"/>
        <DetectChar attribute="Operator" context="#pop" char=")"/>
        <Detect2Chars attribute="Operator" context="RegexSubChar" char="[" char1="^"/>
        <DetectChar attribute="Operator" context="RegexSubChar" char="["/>
        <IncludeRules context="FindRegex"/>
      </context>

      <context attribute="Pattern" lineEndContext="#stay" name="FindRegex">
        <DetectChar attribute="Operator" context="ExprDblBracketSubRegex" char="("/>
        <DetectChar attribute="Escape" context="RegexEscape" char="\"/>
        <DetectChar attribute="Parameter Expansion" context="RegexDup" char="{"/>
        <AnyChar attribute="Glob" context="#stay" String="^?+*.|"/>
        <IncludeRules context="FindStrings"/>
        <DetectChar context="RegexDispatchVariables" char="$" lookAhead="1"/>
        <DetectChar attribute="Backquote" context="RegularBackq" char="`"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#stay" name="RegexDispatchVariables">
        <IncludeRules context="DispatchVariables"/>
        <DetectChar attribute="Operator" context="#pop" char="$"/>
      </context>

      <context attribute="Normal Text" lineEndContext="#pop" name="RegexEscape">
        <RegExpr attribute="Escape" context="#pop" String="x[0-9a-fA-F]{1,2}|[0-7]{1,3}|."/>
      </context>

      <context attribute="Normal Text" lineEndContext="#pop" name="RegexDup">
        <Int attribute="Decimal" additionalDeliminator="{"/>
        <DetectChar attribute="Parameter Expansion Operator" context="#stay" char=","/>
        <DetectChar attribute="Parameter Expansion" context="#pop" char="}"/>
      </context>

      <context attribute="Pattern" lineEndContext="#pop" name="RegexSubChar" fallthroughContext="#pop!RegexSubInChar">
        <AnyChar attribute="Pattern" context="#pop!RegexSubInChar" String="-]"/>
      </context>
      <context attribute="Pattern" lineEndContext="#pop" name="RegexSubInChar">
        <DetectSpaces attribute="Pattern" context="#stay"/>
        <IncludeRules context="RegexInChar"/>
      </context>

      <context attribute="Pattern" lineEndContext="#pop" name="RegexChar" fallthroughContext="#pop!RegexInChar">
        <AnyChar attribute="Pattern" context="#pop!RegexInChar" String="-]"/>
      </context>
      <context attribute="Pattern" lineEndContext="#pop" name="RegexInChar">
        <Detect2Chars context="RegexInCharEnd" char="-" char1="]" lookAhead="1"/>
        <DetectChar attribute="Operator" context="#stay" char="-"/>
        <DetectChar attribute="Escape" context="RegexEscape" char="\"/>
        <DetectChar context="RegexCharClassSelect" char="[" lookAhead="1"/>
        <DetectChar attribute="Operator" context="#pop" char="]"/>
        <AnyChar context="#pop" String="() &tab;" lookAhead="1"/>
        <IncludeRules context="FindStrings"/>
      </context>
      <context attribute="Operator" lineEndContext="#stay" name="RegexInCharEnd">
        <DetectChar attribute="Pattern" context="#stay" char="-"/>
        <DetectChar attribute="Operator" context="#pop#pop" char="]"/>
      </context>
      <context attribute="Parameter Expansion" lineEndContext="#pop#pop#pop" name="RegexCharClassSelect">
        <Detect2Chars attribute="Parameter Expansion Operator" context="#pop!RegexCharClass" char="[" char1=":"/>
        <Detect2Chars attribute="Parameter Expansion Operator" context="#pop!RegexCollatingSymbols" char="[" char1="."/>
        <Detect2Chars attribute="Parameter Expansion Operator" context="#pop!RegexEquivalenceClass" char="[" char1="="/>
        <DetectChar attribute="Pattern" context="#pop" char="["/>
      </context>

      <context attribute="Parameter Expansion" lineEndContext="#pop#pop#pop" name="RegexCharClass">
        <DetectIdentifier attribute="Parameter Expansion"/>
        <Detect2Chars attribute="Parameter Expansion Operator" context="#pop" char=":" char1="]"/>
        <DetectChar attribute="Error" context="#pop" char="]"/>
      </context>
      <context attribute="Parameter Expansion" lineEndContext="#pop#pop#pop" name="RegexCollatingSymbols">
        <DetectIdentifier attribute="Parameter Expansion"/>
        <Detect2Chars attribute="Parameter Expansion Operator" context="#pop" char="." char1="]"/>
        <DetectChar attribute="Error" context="#pop" char="]"/>
      </context>
      <context attribute="Parameter Expansion" lineEndContext="#pop#pop#pop" name="RegexEquivalenceClass">
        <DetectIdentifier attribute="Parameter Expansion"/>
        <Detect2Chars attribute="Parameter Expansion Operator" context="#pop" char="=" char1="]"/>
        <DetectChar attribute="Error" context="#pop" char="]"/>
      </context>

      <!-- SubShell consumes shell input till ) in (...) -->
      <context attribute="Normal Text" lineEndContext="#stay" name="SubShell" fallthroughContext="Command">
        <DetectChar attribute="Keyword" context="#pop" char=")" endRegion="subshell"/>
        <IncludeRules context="Start"/>
      </context>

      <!-- Assign consumes an expression till EOL or whitespace -->
      <context attribute="Normal Text" lineEndContext="#pop" name="Assign" fallthroughContext="#pop!Assign2">
        <DetectChar attribute="Variable" context="#pop!AssignArray" char="("/>
      </context>
      <context attribute="Normal Text" lineEndContext="#pop" name="Assign2" fallthroughContext="#pop">
        <DetectChar attribute="Backquote" context="RegularBackq" char="`"/>
        <IncludeRules context="NormalOption"/>
      </context>

      <!-- AssignArray consumes everything till ) in var=(...), marking assignments -->
      <context attribute="Normal Text" lineEndContext="#stay" name="AssignArray" fallthroughContext="NormalOption">
        <DetectSpaces attribute="Normal Text" context="#stay"/>
        <DetectChar attribute="Comment" context="Comment" char="#"/>
        <DetectChar attribute="Variable" context="#pop!Assign2" char=")"/>
        <DetectChar context="AssignArrayKey" char="[" lookAhead="1"/>
        <DetectChar attribute="Backquote" context="AssignArrayBackq" char="`"/>
        <AnyChar attribute="Error" context="#stay" String="&symbolseps;"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#pop" name="AssignArrayKey" fallthroughContext="#pop">
        <DetectChar attribute="Parameter Expansion Operator" context="Subscript" char="["/>
        <DetectChar attribute="Variable" context="#pop" char="="/>
      </context>
      <context attribute="Normal Text" lineEndContext="#stay" name="AssignArrayBackq" fallthroughContext="Command">
        <DetectChar attribute="Backquote" context="#pop!NormalOption" char="`"/>
        <DetectChar attribute="Comment" context="CommentBackq" char="#"/>
        <IncludeRules context="Start"/>
      </context>

      <!-- Subscript consumes anything till ] in [ ... ], marks as Variable -->
      <context attribute="Normal Text" lineEndContext="#stay" name="Subscript" fallthroughContext="#pop!Subscript2">
        <DetectChar attribute="Parameter Expansion Operator" context="#pop" char="]"/>
        <AnyChar attribute="Decimal" context="#stay" String="0123456789"/>
      </context>
      <context attribute="Normal Text" lineEndContext="#stay" name="Subscript2">
        <DetectIdentifier attribute="Normal Text"/>
        <DetectChar attribute="Parameter Expansion Operator" context="#pop" char="]"/>
        <IncludeRules context="FindWord"/>
        <IncludeRules context="FindPattern"/>
      </context>

      <!-- FunctionDef consumes a name, possibly with (), marks as Function -->
      <context attribute="Function" lineEndContext="#pop" name="FunctionDef" fallthroughContext="#pop">
        <RegExpr attribute="Function" context="#pop" String="[ &tab;]+&funcname;(?:[ &tab;]*\(\))?"/>
      </context>

      <!-- Case is called after the case keyword is encoutered. We handle this because of
           the lonely closing parentheses that would otherwise disturb the expr matching -->
      <context attribute="Normal Text" lineEndContext="#stay" name="Case">
        <DetectSpaces attribute="Normal Text" context="#stay"/>
        <WordDetect attribute="Keyword" context="#pop!CaseIn" String="in"/>
        <IncludeRules context="FindWord"/>
        <DetectIdentifier attribute="Normal Text" context="#stay"/>
      </context>

      <!-- CaseIn is called when the construct 'case ... in' has been found. -->
      <context attribute="Normal Text" lineEndContext="#stay" name="CaseIn" fallthroughContext="CasePattern">
        <DetectSpaces attribute="Normal Text" context="#stay"/>
        <DetectChar attribute="Keyword" context="CasePattern" char="("/>
        <DetectChar attribute="Comment" context="Comment" char="#"/>
      </context>
      <context attribute="Pattern" lineEndContext="#stay" name="CasePattern">
        <DetectSpaces attribute="Normal Text" context="#stay"/>
        <DetectChar attribute="Keyword" context="#pop!CaseExpr" char=")" beginRegion="caseexpr"/>
        <DetectChar context="AssumeEscape" char="\" lookAhead="1"/>
        <DetectChar attribute="Keyword" context="#stay" char="|"/>
        <IncludeRules context="FindWord"/>
        <IncludeRules context="FindPattern"/>
        <WordDetect attribute="Control Flow" context="#pop#pop" String="esac" endRegion="case"/>
        <DetectIdentifier attribute="Pattern" context="#stay"/>
      </context>

      <!-- CaseExpr eats shell input till ;; / ;& / ;;& -->
      <context attribute="Normal Text" lineEndContext="#stay" name="CaseExpr" fallthroughContext="Command">
        <StringDetect attribute="Control Flow" context="#pop" String=";;&amp;" endRegion="caseexpr"/>
        <Detect2Chars attribute="Control Flow" context="#pop" char=";" char1=";" endRegion="caseexpr"/>
        <Detect2Chars attribute="Control Flow" context="#pop" char=";" char1="&amp;" endRegion="caseexpr"/>
        <WordDetect context="#pop" String="esac" endRegion="caseexpr" lookAhead="1"/>
        <IncludeRules context="Start"/>
      </context>

    </contexts>

    <itemDatas>
      <itemData name="Normal Text"    defStyleNum="dsNormal"/>
      <itemData name="Comment"        defStyleNum="dsComment"/>
      <itemData name="Keyword"        defStyleNum="dsKeyword"       spellChecking="false"/>
      <itemData name="Control"        defStyleNum="dsKeyword"       spellChecking="false"/>
      <itemData name="Control Flow"   defStyleNum="dsControlFlow"   spellChecking="false"/>
      <itemData name="Builtin"        defStyleNum="dsBuiltIn"       spellChecking="false"/>
      <itemData name="Command"        defStyleNum="dsFunction"      spellChecking="false"/>
      <itemData name="OtherCommand"   defStyleNum="dsExtension"     spellChecking="false"/>
      <itemData name="Redirection"    defStyleNum="dsOperator"      spellChecking="false"/>
      <itemData name="Escape"         defStyleNum="dsDataType"      spellChecking="false"/>
      <itemData name="String SingleQ" defStyleNum="dsString"/>
      <itemData name="String DoubleQ" defStyleNum="dsString"/>
      <itemData name="Here Doc"       defStyleNum="dsString"/>
      <itemData name="Backquote"      defStyleNum="dsKeyword"       spellChecking="false"/>
      <itemData name="String Transl." defStyleNum="dsString"/>
      <itemData name="String Escape"  defStyleNum="dsDataType"/>
      <itemData name="Variable"       defStyleNum="dsVariable"      spellChecking="false"/>
      <itemData name="Dollar Prefix"  defStyleNum="dsVariable"      spellChecking="false"/>
      <itemData name="Expression"     defStyleNum="dsOthers"        spellChecking="false"/>
      <itemData name="Function"       defStyleNum="dsFunction"      spellChecking="false"/>
      <itemData name="Pattern"        defStyleNum="dsSpecialString" spellChecking="false"/>
      <itemData name="Path"           defStyleNum="dsNormal"        spellChecking="false"/>
      <itemData name="Glob"           defStyleNum="dsPreprocessor"  spellChecking="false"/>
      <itemData name="Option"         defStyleNum="dsAttribute"     spellChecking="false"/>
      <itemData name="Hex"            defStyleNum="dsBaseN"         spellChecking="false"/>
      <itemData name="Octal"          defStyleNum="dsBaseN"         spellChecking="false"/>
      <itemData name="Decimal"        defStyleNum="dsDecVal"        spellChecking="false"/>
      <itemData name="Base"           defStyleNum="dsDataType"      spellChecking="false"/>
      <itemData name="BaseN"          defStyleNum="dsBaseN"         spellChecking="false"/>
      <itemData name="File Descriptor" defStyleNum="dsDecVal"       spellChecking="false"/>
      <itemData name="Parameter Expansion" defStyleNum="dsVariable" spellChecking="false"/>
      <itemData name="Parameter Expansion Operator" defStyleNum="dsOperator" spellChecking="false"/>
      <itemData name="Operator"       defStyleNum="dsOperator"      spellChecking="false"/>
      <itemData name="Error"          defStyleNum="dsError"         spellChecking="false"/>
      <itemData name="Region Marker"  defStyleNum="dsRegionMarker"  spellChecking="false" />
    </itemDatas>
  </highlighting>
  <general>
    <comments>
      <comment name="singleLine" start="#"/>
    </comments>
    <keywords casesensitive="1" weakDeliminator="_&weakDeliminatorSymbols;" additionalDeliminator="`"/>
  </general>
</language>
<!-- kate: replace-tabs on; tab-width 2; indent-width 2; -->
