just-bash 2.9.3 → 2.9.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/chunks/{chunk-2ODUA7YH.js → chunk-B3E7BBYK.js} +36 -36
- package/dist/bin/chunks/{expansion-QOAPT4NU.js → expansion-LR5H7O2U.js} +1 -1
- package/dist/bin/chunks/worker.js +157 -1
- package/dist/bin/just-bash.js +138 -138
- package/dist/bin/shell/chunks/{chunk-2ODUA7YH.js → chunk-B3E7BBYK.js} +36 -36
- package/dist/bin/shell/chunks/{expansion-QOAPT4NU.js → expansion-LR5H7O2U.js} +1 -1
- package/dist/bin/shell/shell.js +144 -144
- package/dist/bundle/browser.js +455 -455
- package/dist/bundle/chunks/{chunk-2AON5K3E.js → chunk-RERCNF7Z.js} +36 -36
- package/dist/bundle/chunks/{expansion-7IMG6HKQ.js → expansion-OFFC2R4K.js} +1 -1
- package/dist/bundle/chunks/worker.js +157 -1
- package/dist/bundle/index.js +166 -166
- package/dist/parser/parser.d.ts +6 -0
- package/dist/parser/types.d.ts +1 -0
- package/package.json +4 -4
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{e as H,f as j,g as C,h as re,i as Pe,j as
|
|
3
|
-
`){t+=2;continue}if(/\s/.test(e[t])){t++;continue}break}return t}var Re=["=","+=","-=","*=","/=","%=","<<=",">>=","&=","|=","^="];function me(e){if(e.includes("#")){let[t,r]=e.split("#"),s=Number.parseInt(t,10);if(s<2||s>64)return Number.NaN;if(s<=36)return Number.parseInt(r,s);let n=0;for(let a of r){let i;if(/[0-9]/.test(a))i=a.charCodeAt(0)-48;else if(/[a-z]/.test(a))i=a.charCodeAt(0)-97+10;else if(/[A-Z]/.test(a))i=a.charCodeAt(0)-65+36;else if(a==="@")i=62;else if(a==="_")i=63;else return Number.NaN;if(i>=s)return Number.NaN;n=n*s+i}return n}return e.startsWith("0x")||e.startsWith("0X")?Number.parseInt(e.slice(2),16):e.startsWith("0")&&e.length>1&&/^[0-9]+$/.test(e)?/[89]/.test(e)?Number.NaN:Number.parseInt(e,8):Number.parseInt(e,10)}function
|
|
4
|
-
`;break;case"t":s+=" ";break;case"r":s+="\r";break;case"\\":s+="\\";break;case"'":s+="'";break;default:s+=a}r+=2}else s+=e[r],r++;e[r]==="'"&&r++;let n=Number.parseInt(s,10);return{expr:{type:"ArithNumber",value:Number.isNaN(n)?0:n},pos:r}}function Dt(e,t){if(e.slice(t,t+2)!=='$"')return null;let r=t+2,s="";for(;r<e.length&&e[r]!=='"';)e[r]==="\\"&&r+1<e.length?(s+=e[r+1],r+=2):(s+=e[r],r++);e[r]==='"'&&r++;let n=Number.parseInt(s,10);return{expr:{type:"ArithNumber",value:Number.isNaN(n)?0:n},pos:r}}function wr(e){let t="",r=0;for(;r<e.length;)if(e[r]==='"'){for(r++;r<e.length&&e[r]!=='"';)e[r]==="\\"&&r+1<e.length?(t+=e[r+1],r+=2):(t+=e[r],r++);r<e.length&&r++}else t+=e[r],r++;return t}function T(e,t){let r=wr(t),{expr:s,pos:n}=Z(e,r,0),a=_(r,n);if(a<r.length){let i=t.slice(a).trim();if(i)return{type:"ArithmeticExpression",originalText:t,expression:{type:"ArithSyntaxError",errorToken:i,message:`${i}: syntax error: invalid arithmetic operator (error token is "${i}")`}}}return{type:"ArithmeticExpression",expression:s,originalText:t}}function F(e,t){return{expr:{type:"ArithSyntaxError",errorToken:e,message:`syntax error: operand expected (error token is "${e}")`},pos:t}}function Q(e,t){return _(e,t)>=e.length}function Z(e,t,r){return Nr(e,t,r)}function Nr(e,t,r){let{expr:s,pos:n}=ge(e,t,r);for(n=_(t,n);t[n]===",";){if(n++,Q(t,n))return F(",",n);let{expr:i,pos:l}=ge(e,t,n);s={type:"ArithBinary",operator:",",left:s,right:i},n=_(t,l)}return{expr:s,pos:n}}function ge(e,t,r){let{expr:s,pos:n}=kr(e,t,r);if(n=_(t,n),t[n]==="?"){n++;let{expr:a,pos:i}=Z(e,t,n);if(n=_(t,i),t[n]===":"){n++;let{expr:l,pos:o}=Z(e,t,n);return{expr:{type:"ArithTernary",condition:s,consequent:a,alternate:l},pos:o}}}return{expr:s,pos:n}}function kr(e,t,r){let{expr:s,pos:n}=xt(e,t,r);for(;n=_(t,n),t.slice(n,n+2)==="||";){if(n+=2,Q(t,n))return F("||",n);let{expr:i,pos:l}=xt(e,t,n);s={type:"ArithBinary",operator:"||",left:s,right:i},n=l}return{expr:s,pos:n}}function xt(e,t,r){let{expr:s,pos:n}=$t(e,t,r);for(;n=_(t,n),t.slice(n,n+2)==="&&";){if(n+=2,Q(t,n))return F("&&",n);let{expr:i,pos:l}=$t(e,t,n);s={type:"ArithBinary",operator:"&&",left:s,right:i},n=l}return{expr:s,pos:n}}function $t(e,t,r){let{expr:s,pos:n}=_t(e,t,r);for(;n=_(t,n),t[n]==="|"&&t[n+1]!=="|";){if(n++,Q(t,n))return F("|",n);let{expr:i,pos:l}=_t(e,t,n);s={type:"ArithBinary",operator:"|",left:s,right:i},n=l}return{expr:s,pos:n}}function _t(e,t,r){let{expr:s,pos:n}=Ct(e,t,r);for(;n=_(t,n),t[n]==="^";){if(n++,Q(t,n))return F("^",n);let{expr:i,pos:l}=Ct(e,t,n);s={type:"ArithBinary",operator:"^",left:s,right:i},n=l}return{expr:s,pos:n}}function Ct(e,t,r){let{expr:s,pos:n}=Ot(e,t,r);for(;n=_(t,n),t[n]==="&"&&t[n+1]!=="&";){if(n++,Q(t,n))return F("&",n);let{expr:i,pos:l}=Ot(e,t,n);s={type:"ArithBinary",operator:"&",left:s,right:i},n=l}return{expr:s,pos:n}}function Ot(e,t,r){let{expr:s,pos:n}=Lt(e,t,r);for(;n=_(t,n),t.slice(n,n+2)==="=="||t.slice(n,n+2)==="!=";){let a=t.slice(n,n+2);if(n+=2,Q(t,n))return F(a,n);let{expr:i,pos:l}=Lt(e,t,n);s={type:"ArithBinary",operator:a,left:s,right:i},n=l}return{expr:s,pos:n}}function Lt(e,t,r){let{expr:s,pos:n}=Qe(e,t,r);for(;;)if(n=_(t,n),t.slice(n,n+2)==="<="||t.slice(n,n+2)===">="){let a=t.slice(n,n+2);if(n+=2,Q(t,n))return F(a,n);let{expr:i,pos:l}=Qe(e,t,n);s={type:"ArithBinary",operator:a,left:s,right:i},n=l}else if(t[n]==="<"||t[n]===">"){let a=t[n];if(n++,Q(t,n))return F(a,n);let{expr:i,pos:l}=Qe(e,t,n);s={type:"ArithBinary",operator:a,left:s,right:i},n=l}else break;return{expr:s,pos:n}}function Qe(e,t,r){let{expr:s,pos:n}=Wt(e,t,r);for(;n=_(t,n),t.slice(n,n+2)==="<<"||t.slice(n,n+2)===">>";){let a=t.slice(n,n+2);if(n+=2,Q(t,n))return F(a,n);let{expr:i,pos:l}=Wt(e,t,n);s={type:"ArithBinary",operator:a,left:s,right:i},n=l}return{expr:s,pos:n}}function Wt(e,t,r){let{expr:s,pos:n}=Tt(e,t,r);for(;n=_(t,n),(t[n]==="+"||t[n]==="-")&&t[n+1]!==t[n];){let a=t[n];if(n++,Q(t,n))return F(a,n);let{expr:i,pos:l}=Tt(e,t,n);s={type:"ArithBinary",operator:a,left:s,right:i},n=l}return{expr:s,pos:n}}function Tt(e,t,r){let{expr:s,pos:n}=Ie(e,t,r);for(;;)if(n=_(t,n),t[n]==="*"&&t[n+1]!=="*"){if(n++,Q(t,n))return F("*",n);let{expr:i,pos:l}=Ie(e,t,n);s={type:"ArithBinary",operator:"*",left:s,right:i},n=l}else if(t[n]==="/"||t[n]==="%"){let a=t[n];if(n++,Q(t,n))return F(a,n);let{expr:i,pos:l}=Ie(e,t,n);s={type:"ArithBinary",operator:a,left:s,right:i},n=l}else break;return{expr:s,pos:n}}function Ie(e,t,r){let{expr:s,pos:n}=ze(e,t,r),a=_(t,n);if(t.slice(a,a+2)==="**"){if(a+=2,Q(t,a))return F("**",a);let{expr:l,pos:o}=Ie(e,t,a);return{expr:{type:"ArithBinary",operator:"**",left:s,right:l},pos:o}}return{expr:s,pos:n}}function ze(e,t,r){let s=_(t,r);if(t.slice(s,s+2)==="++"||t.slice(s,s+2)==="--"){let n=t.slice(s,s+2);s+=2;let{expr:a,pos:i}=ze(e,t,s);return{expr:{type:"ArithUnary",operator:n,operand:a,prefix:!0},pos:i}}if(t[s]==="+"||t[s]==="-"||t[s]==="!"||t[s]==="~"){let n=t[s];s++;let{expr:a,pos:i}=ze(e,t,s);return{expr:{type:"ArithUnary",operator:n,operand:a,prefix:!0},pos:i}}return Rr(e,t,s)}function Pr(e,t){let r=e[t];return r==="$"||r==="`"}function Rr(e,t,r){let{expr:s,pos:n}=Mt(e,t,r,!1),a=[s];for(;Pr(t,n);){let{expr:l,pos:o}=Mt(e,t,n,!0);a.push(l),n=o}a.length>1&&(s={type:"ArithConcat",parts:a});let i;if(t[n]==="["&&s.type==="ArithConcat"){n++;let{expr:l,pos:o}=Z(e,t,n);i=l,n=o,t[n]==="]"&&n++}if(i&&s.type==="ArithConcat"&&(s={type:"ArithDynamicElement",nameExpr:s,subscript:i},i=void 0),n=_(t,n),s.type==="ArithConcat"||s.type==="ArithVariable"||s.type==="ArithDynamicElement"){for(let l of Re)if(t.slice(n,n+l.length)===l&&t.slice(n,n+l.length+1)!=="=="){n+=l.length;let{expr:o,pos:u}=ge(e,t,n);return s.type==="ArithDynamicElement"?{expr:{type:"ArithDynamicAssignment",operator:l,target:s.nameExpr,subscript:s.subscript,value:o},pos:u}:s.type==="ArithConcat"?{expr:{type:"ArithDynamicAssignment",operator:l,target:s,value:o},pos:u}:{expr:{type:"ArithAssignment",operator:l,variable:s.name,value:o},pos:u}}}if(t.slice(n,n+2)==="++"||t.slice(n,n+2)==="--"){let l=t.slice(n,n+2);return n+=2,{expr:{type:"ArithUnary",operator:l,operand:s,prefix:!1},pos:n}}return{expr:s,pos:n}}function Mt(e,t,r,s=!1){let n=_(t,r),a=It(Z,e,t,n);if(a)return a;let i=vt(t,n);if(i)return i;let l=Dt(t,n);if(l)return l;if(t.slice(n,n+2)==="$("&&t[n+2]!=="("){n+=2;let u=1,c=n;for(;n<t.length&&u>0;)t[n]==="("?u++:t[n]===")"&&u--,u>0&&n++;let f=t.slice(c,n);return n++,{expr:{type:"ArithCommandSubst",command:f},pos:n}}if(t[n]==="`"){n++;let u=n;for(;n<t.length&&t[n]!=="`";)n++;let c=t.slice(u,n);return t[n]==="`"&&n++,{expr:{type:"ArithCommandSubst",command:c},pos:n}}if(t[n]==="("){n++;let{expr:u,pos:c}=Z(e,t,n);return n=_(t,c),t[n]===")"&&n++,{expr:{type:"ArithGroup",expression:u},pos:n}}if(t[n]==="'"){n++;let u="";for(;n<t.length&&t[n]!=="'";)u+=t[n],n++;t[n]==="'"&&n++;let c=Number.parseInt(u,10);return{expr:{type:"ArithSingleQuote",content:u,value:Number.isNaN(c)?0:c},pos:n}}if(t[n]==='"'){n++;let u="";for(;n<t.length&&t[n]!=='"';)t[n]==="\\"&&n+1<t.length?(u+=t[n+1],n+=2):(u+=t[n],n++);t[n]==='"'&&n++;let c=u.trim();if(!c)return{expr:{type:"ArithNumber",value:0},pos:n};let{expr:f}=Z(e,c,0);return{expr:f,pos:n}}if(/[0-9]/.test(t[n])){let u="",c=!1,f=!1;for(;n<t.length;){let d=t[n];if(c)if(/[0-9a-zA-Z@_]/.test(d))u+=d,n++;else break;else if(d==="#")c=!0,u+=d,n++;else if(u==="0"&&(d==="x"||d==="X")&&n+1<t.length&&/[0-9a-fA-F]/.test(t[n+1]))f=!0,u+=d,n++;else if(f&&/[0-9a-fA-F]/.test(d))u+=d,n++;else if(!f&&/[0-9]/.test(d))u+=d,n++;else break}if(n<t.length&&/[a-zA-Z_]/.test(t[n])){let d=u;for(;n<t.length&&/[a-zA-Z0-9_]/.test(t[n]);)d+=t[n],n++;return{expr:{type:"ArithSyntaxError",errorToken:d,message:`${d}: value too great for base (error token is "${d}")`},pos:n}}if(t[n]==="."&&/[0-9]/.test(t[n+1]))throw new C(`${u}.${t[n+1]}...: syntax error: invalid arithmetic operator`);if(t[n]==="["){let d=t.slice(n).trim();return{expr:{type:"ArithNumberSubscript",number:u,errorToken:d},pos:t.length}}return{expr:{type:"ArithNumber",value:me(u)},pos:n}}if(t[n]==="$"&&t[n+1]==="{"){let u=n+2,c=1,f=u;for(;f<t.length&&c>0;)t[f]==="{"?c++:t[f]==="}"&&c--,c>0&&f++;let p=t.slice(u,f),d=f+1;if(t[d]==="#"){let g=d+1;for(;g<t.length&&/[0-9a-zA-Z@_]/.test(t[g]);)g++;let m=t.slice(d+1,g);return{expr:{type:"ArithDynamicBase",baseExpr:p,value:m},pos:g}}if(/[0-9]/.test(t[d])||t[d]==="x"||t[d]==="X"){let g=d;if(t[d]==="x"||t[d]==="X")for(g++;g<t.length&&/[0-9a-fA-F]/.test(t[g]);)g++;else for(;g<t.length&&/[0-9]/.test(t[g]);)g++;let m=t.slice(d,g);return{expr:{type:"ArithDynamicNumber",prefix:p,suffix:m},pos:g}}return n=d,{expr:{type:"ArithBracedExpansion",content:p},pos:n}}if(t[n]==="$"&&n+1<t.length&&/[0-9]/.test(t[n+1])){n++;let u="";for(;n<t.length&&/[0-9]/.test(t[n]);)u+=t[n],n++;return{expr:{type:"ArithVariable",name:u,hasDollarPrefix:!0},pos:n}}if(t[n]==="$"&&n+1<t.length&&/[*@#?\-!$]/.test(t[n+1])){let u=t[n+1];return n+=2,{expr:{type:"ArithSpecialVar",name:u},pos:n}}let o=!1;if(t[n]==="$"&&n+1<t.length&&/[a-zA-Z_]/.test(t[n+1])&&(o=!0,n++),n<t.length&&/[a-zA-Z_]/.test(t[n])){let u="";for(;n<t.length&&/[a-zA-Z0-9_]/.test(t[n]);)u+=t[n],n++;if(t[n]==="["&&!s){n++;let c;if(t[n]==="'"||t[n]==='"'){let p=t[n];for(n++,c="";n<t.length&&t[n]!==p;)c+=t[n],n++;t[n]===p&&n++,n=_(t,n),t[n]==="]"&&n++}let f;if(c===void 0){let{expr:p,pos:d}=Z(e,t,n);f=p,n=d,t[n]==="]"&&n++}if(n=_(t,n),t[n]==="["&&f)return{expr:{type:"ArithDoubleSubscript",array:u,index:f},pos:n};if(!s){for(let p of Re)if(t.slice(n,n+p.length)===p&&t.slice(n,n+p.length+1)!=="=="){n+=p.length;let{expr:d,pos:g}=ge(e,t,n);return{expr:{type:"ArithAssignment",operator:p,variable:u,subscript:f,stringKey:c,value:d},pos:g}}}return{expr:{type:"ArithArrayElement",array:u,index:f,stringKey:c},pos:n}}if(n=_(t,n),!s){for(let c of Re)if(t.slice(n,n+c.length)===c&&t.slice(n,n+c.length+1)!=="=="){n+=c.length;let{expr:f,pos:p}=ge(e,t,n);return{expr:{type:"ArithAssignment",operator:c,variable:u,value:f},pos:p}}}return{expr:{type:"ArithVariable",name:u,hasDollarPrefix:o},pos:n}}if(t[n]==="#"){let u=n+1;for(;u<t.length&&t[u]!==`
|
|
5
|
-
`;)u++;let c=t.slice(n,u).trim()||"#";return{expr:{type:"ArithSyntaxError",errorToken:c,message:`${c}: syntax error: invalid arithmetic operator (error token is "${c}")`},pos:t.length}}return{expr:{type:"ArithNumber",value:0},pos:n}}var w={script(e){return{type:"Script",statements:e}},statement(e,t=[],r=!1,s,n){let a={type:"Statement",pipelines:e,operators:t,background:r};return s&&(a.deferredError=s),n!==void 0&&(a.sourceText=n),a},pipeline(e,t=!1,r=!1,s=!1,n){return{type:"Pipeline",commands:e,negated:t,timed:r,timePosix:s,pipeStderr:n}},simpleCommand(e,t=[],r=[],s=[]){return{type:"SimpleCommand",name:e,args:t,assignments:r,redirections:s}},word(e){return{type:"Word",parts:e}},literal(e){return{type:"Literal",value:e}},singleQuoted(e){return{type:"SingleQuoted",value:e}},doubleQuoted(e){return{type:"DoubleQuoted",parts:e}},escaped(e){return{type:"Escaped",value:e}},parameterExpansion(e,t=null){return{type:"ParameterExpansion",parameter:e,operation:t}},commandSubstitution(e,t=!1){return{type:"CommandSubstitution",body:e,legacy:t}},arithmeticExpansion(e){return{type:"ArithmeticExpansion",expression:e}},assignment(e,t,r=!1,s=null){return{type:"Assignment",name:e,value:t,append:r,array:s}},redirection(e,t,r=null,s){let n={type:"Redirection",fd:r,operator:e,target:t};return s&&(n.fdVariable=s),n},hereDoc(e,t,r=!1,s=!1){return{type:"HereDoc",delimiter:e,content:t,stripTabs:r,quoted:s}},ifNode(e,t=null,r=[]){return{type:"If",clauses:e,elseBody:t,redirections:r}},forNode(e,t,r,s=[]){return{type:"For",variable:e,words:t,body:r,redirections:s}},whileNode(e,t,r=[]){return{type:"While",condition:e,body:t,redirections:r}},untilNode(e,t,r=[]){return{type:"Until",condition:e,body:t,redirections:r}},caseNode(e,t,r=[]){return{type:"Case",word:e,items:t,redirections:r}},caseItem(e,t,r=";;"){return{type:"CaseItem",patterns:e,body:t,terminator:r}},subshell(e,t=[]){return{type:"Subshell",body:e,redirections:t}},group(e,t=[]){return{type:"Group",body:e,redirections:t}},functionDef(e,t,r=[],s){return{type:"FunctionDef",name:e,body:t,redirections:r,sourceFile:s}},conditionalCommand(e,t=[],r){return{type:"ConditionalCommand",expression:e,redirections:t,line:r}},arithmeticCommand(e,t=[],r){return{type:"ArithmeticCommand",expression:e,redirections:t,line:r}}};var h;(function(e){e.EOF="EOF",e.NEWLINE="NEWLINE",e.SEMICOLON="SEMICOLON",e.AMP="AMP",e.PIPE="PIPE",e.PIPE_AMP="PIPE_AMP",e.AND_AND="AND_AND",e.OR_OR="OR_OR",e.BANG="BANG",e.LESS="LESS",e.GREAT="GREAT",e.DLESS="DLESS",e.DGREAT="DGREAT",e.LESSAND="LESSAND",e.GREATAND="GREATAND",e.LESSGREAT="LESSGREAT",e.DLESSDASH="DLESSDASH",e.CLOBBER="CLOBBER",e.TLESS="TLESS",e.AND_GREAT="AND_GREAT",e.AND_DGREAT="AND_DGREAT",e.LPAREN="LPAREN",e.RPAREN="RPAREN",e.LBRACE="LBRACE",e.RBRACE="RBRACE",e.DSEMI="DSEMI",e.SEMI_AND="SEMI_AND",e.SEMI_SEMI_AND="SEMI_SEMI_AND",e.DBRACK_START="DBRACK_START",e.DBRACK_END="DBRACK_END",e.DPAREN_START="DPAREN_START",e.DPAREN_END="DPAREN_END",e.IF="IF",e.THEN="THEN",e.ELSE="ELSE",e.ELIF="ELIF",e.FI="FI",e.FOR="FOR",e.WHILE="WHILE",e.UNTIL="UNTIL",e.DO="DO",e.DONE="DONE",e.CASE="CASE",e.ESAC="ESAC",e.IN="IN",e.FUNCTION="FUNCTION",e.SELECT="SELECT",e.TIME="TIME",e.COPROC="COPROC",e.WORD="WORD",e.NAME="NAME",e.NUMBER="NUMBER",e.ASSIGNMENT_WORD="ASSIGNMENT_WORD",e.FD_VARIABLE="FD_VARIABLE",e.COMMENT="COMMENT",e.HEREDOC_CONTENT="HEREDOC_CONTENT"})(h||(h={}));var pe=class extends Error{line;column;constructor(t,r,s){super(`line ${r}: ${t}`),this.line=r,this.column=s,this.name="LexerError"}},
|
|
6
|
-
`||e===";"||e==="&"||e==="|"||e==="("||e===")"||e==="<"||e===">"}var
|
|
2
|
+
import{e as H,f as j,g as C,h as re,i as Pe,j as It,k as B}from"./chunk-K5IXNHO5.js";import{a as O}from"./chunk-SE4C7FJY.js";function _(e,t){for(;t<e.length;){if(e[t]==="\\"&&e[t+1]===`
|
|
3
|
+
`){t+=2;continue}if(/\s/.test(e[t])){t++;continue}break}return t}var Re=["=","+=","-=","*=","/=","%=","<<=",">>=","&=","|=","^="];function me(e){if(e.includes("#")){let[t,r]=e.split("#"),s=Number.parseInt(t,10);if(s<2||s>64)return Number.NaN;if(s<=36)return Number.parseInt(r,s);let n=0;for(let a of r){let i;if(/[0-9]/.test(a))i=a.charCodeAt(0)-48;else if(/[a-z]/.test(a))i=a.charCodeAt(0)-97+10;else if(/[A-Z]/.test(a))i=a.charCodeAt(0)-65+36;else if(a==="@")i=62;else if(a==="_")i=63;else return Number.NaN;if(i>=s)return Number.NaN;n=n*s+i}return n}return e.startsWith("0x")||e.startsWith("0X")?Number.parseInt(e.slice(2),16):e.startsWith("0")&&e.length>1&&/^[0-9]+$/.test(e)?/[89]/.test(e)?Number.NaN:Number.parseInt(e,8):Number.parseInt(e,10)}function Dt(e,t,r,s){if(r.slice(s,s+3)!=="$((")return null;let n=s+3,a=1,i=n;for(;n<r.length-1&&a>0;)r[n]==="("&&r[n+1]==="("?(a++,n+=2):r[n]===")"&&r[n+1]===")"?(a--,a>0&&(n+=2)):n++;let l=r.slice(i,n),{expr:o}=e(t,l,0);return n+=2,{expr:{type:"ArithNested",expression:o},pos:n}}function vt(e,t){if(e.slice(t,t+2)!=="$'")return null;let r=t+2,s="";for(;r<e.length&&e[r]!=="'";)if(e[r]==="\\"&&r+1<e.length){let a=e[r+1];switch(a){case"n":s+=`
|
|
4
|
+
`;break;case"t":s+=" ";break;case"r":s+="\r";break;case"\\":s+="\\";break;case"'":s+="'";break;default:s+=a}r+=2}else s+=e[r],r++;e[r]==="'"&&r++;let n=Number.parseInt(s,10);return{expr:{type:"ArithNumber",value:Number.isNaN(n)?0:n},pos:r}}function xt(e,t){if(e.slice(t,t+2)!=='$"')return null;let r=t+2,s="";for(;r<e.length&&e[r]!=='"';)e[r]==="\\"&&r+1<e.length?(s+=e[r+1],r+=2):(s+=e[r],r++);e[r]==='"'&&r++;let n=Number.parseInt(s,10);return{expr:{type:"ArithNumber",value:Number.isNaN(n)?0:n},pos:r}}function Nr(e){let t="",r=0;for(;r<e.length;)if(e[r]==='"'){for(r++;r<e.length&&e[r]!=='"';)e[r]==="\\"&&r+1<e.length?(t+=e[r+1],r+=2):(t+=e[r],r++);r<e.length&&r++}else t+=e[r],r++;return t}function T(e,t){let r=Nr(t),{expr:s,pos:n}=G(e,r,0),a=_(r,n);if(a<r.length){let i=t.slice(a).trim();if(i)return{type:"ArithmeticExpression",originalText:t,expression:{type:"ArithSyntaxError",errorToken:i,message:`${i}: syntax error: invalid arithmetic operator (error token is "${i}")`}}}return{type:"ArithmeticExpression",expression:s,originalText:t}}function F(e,t){return{expr:{type:"ArithSyntaxError",errorToken:e,message:`syntax error: operand expected (error token is "${e}")`},pos:t}}function Q(e,t){return _(e,t)>=e.length}function G(e,t,r){return kr(e,t,r)}function kr(e,t,r){let{expr:s,pos:n}=ge(e,t,r);for(n=_(t,n);t[n]===",";){if(n++,Q(t,n))return F(",",n);let{expr:i,pos:l}=ge(e,t,n);s={type:"ArithBinary",operator:",",left:s,right:i},n=_(t,l)}return{expr:s,pos:n}}function ge(e,t,r){let{expr:s,pos:n}=Pr(e,t,r);if(n=_(t,n),t[n]==="?"){n++;let{expr:a,pos:i}=G(e,t,n);if(n=_(t,i),t[n]===":"){n++;let{expr:l,pos:o}=G(e,t,n);return{expr:{type:"ArithTernary",condition:s,consequent:a,alternate:l},pos:o}}}return{expr:s,pos:n}}function Pr(e,t,r){let{expr:s,pos:n}=$t(e,t,r);for(;n=_(t,n),t.slice(n,n+2)==="||";){if(n+=2,Q(t,n))return F("||",n);let{expr:i,pos:l}=$t(e,t,n);s={type:"ArithBinary",operator:"||",left:s,right:i},n=l}return{expr:s,pos:n}}function $t(e,t,r){let{expr:s,pos:n}=_t(e,t,r);for(;n=_(t,n),t.slice(n,n+2)==="&&";){if(n+=2,Q(t,n))return F("&&",n);let{expr:i,pos:l}=_t(e,t,n);s={type:"ArithBinary",operator:"&&",left:s,right:i},n=l}return{expr:s,pos:n}}function _t(e,t,r){let{expr:s,pos:n}=Ct(e,t,r);for(;n=_(t,n),t[n]==="|"&&t[n+1]!=="|";){if(n++,Q(t,n))return F("|",n);let{expr:i,pos:l}=Ct(e,t,n);s={type:"ArithBinary",operator:"|",left:s,right:i},n=l}return{expr:s,pos:n}}function Ct(e,t,r){let{expr:s,pos:n}=Ot(e,t,r);for(;n=_(t,n),t[n]==="^";){if(n++,Q(t,n))return F("^",n);let{expr:i,pos:l}=Ot(e,t,n);s={type:"ArithBinary",operator:"^",left:s,right:i},n=l}return{expr:s,pos:n}}function Ot(e,t,r){let{expr:s,pos:n}=Lt(e,t,r);for(;n=_(t,n),t[n]==="&"&&t[n+1]!=="&";){if(n++,Q(t,n))return F("&",n);let{expr:i,pos:l}=Lt(e,t,n);s={type:"ArithBinary",operator:"&",left:s,right:i},n=l}return{expr:s,pos:n}}function Lt(e,t,r){let{expr:s,pos:n}=Wt(e,t,r);for(;n=_(t,n),t.slice(n,n+2)==="=="||t.slice(n,n+2)==="!=";){let a=t.slice(n,n+2);if(n+=2,Q(t,n))return F(a,n);let{expr:i,pos:l}=Wt(e,t,n);s={type:"ArithBinary",operator:a,left:s,right:i},n=l}return{expr:s,pos:n}}function Wt(e,t,r){let{expr:s,pos:n}=Qe(e,t,r);for(;;)if(n=_(t,n),t.slice(n,n+2)==="<="||t.slice(n,n+2)===">="){let a=t.slice(n,n+2);if(n+=2,Q(t,n))return F(a,n);let{expr:i,pos:l}=Qe(e,t,n);s={type:"ArithBinary",operator:a,left:s,right:i},n=l}else if(t[n]==="<"||t[n]===">"){let a=t[n];if(n++,Q(t,n))return F(a,n);let{expr:i,pos:l}=Qe(e,t,n);s={type:"ArithBinary",operator:a,left:s,right:i},n=l}else break;return{expr:s,pos:n}}function Qe(e,t,r){let{expr:s,pos:n}=Tt(e,t,r);for(;n=_(t,n),t.slice(n,n+2)==="<<"||t.slice(n,n+2)===">>";){let a=t.slice(n,n+2);if(n+=2,Q(t,n))return F(a,n);let{expr:i,pos:l}=Tt(e,t,n);s={type:"ArithBinary",operator:a,left:s,right:i},n=l}return{expr:s,pos:n}}function Tt(e,t,r){let{expr:s,pos:n}=Mt(e,t,r);for(;n=_(t,n),(t[n]==="+"||t[n]==="-")&&t[n+1]!==t[n];){let a=t[n];if(n++,Q(t,n))return F(a,n);let{expr:i,pos:l}=Mt(e,t,n);s={type:"ArithBinary",operator:a,left:s,right:i},n=l}return{expr:s,pos:n}}function Mt(e,t,r){let{expr:s,pos:n}=Ie(e,t,r);for(;;)if(n=_(t,n),t[n]==="*"&&t[n+1]!=="*"){if(n++,Q(t,n))return F("*",n);let{expr:i,pos:l}=Ie(e,t,n);s={type:"ArithBinary",operator:"*",left:s,right:i},n=l}else if(t[n]==="/"||t[n]==="%"){let a=t[n];if(n++,Q(t,n))return F(a,n);let{expr:i,pos:l}=Ie(e,t,n);s={type:"ArithBinary",operator:a,left:s,right:i},n=l}else break;return{expr:s,pos:n}}function Ie(e,t,r){let{expr:s,pos:n}=ze(e,t,r),a=_(t,n);if(t.slice(a,a+2)==="**"){if(a+=2,Q(t,a))return F("**",a);let{expr:l,pos:o}=Ie(e,t,a);return{expr:{type:"ArithBinary",operator:"**",left:s,right:l},pos:o}}return{expr:s,pos:n}}function ze(e,t,r){let s=_(t,r);if(t.slice(s,s+2)==="++"||t.slice(s,s+2)==="--"){let n=t.slice(s,s+2);s+=2;let{expr:a,pos:i}=ze(e,t,s);return{expr:{type:"ArithUnary",operator:n,operand:a,prefix:!0},pos:i}}if(t[s]==="+"||t[s]==="-"||t[s]==="!"||t[s]==="~"){let n=t[s];s++;let{expr:a,pos:i}=ze(e,t,s);return{expr:{type:"ArithUnary",operator:n,operand:a,prefix:!0},pos:i}}return Ir(e,t,s)}function Rr(e,t){let r=e[t];return r==="$"||r==="`"}function Ir(e,t,r){let{expr:s,pos:n}=Vt(e,t,r,!1),a=[s];for(;Rr(t,n);){let{expr:l,pos:o}=Vt(e,t,n,!0);a.push(l),n=o}a.length>1&&(s={type:"ArithConcat",parts:a});let i;if(t[n]==="["&&s.type==="ArithConcat"){n++;let{expr:l,pos:o}=G(e,t,n);i=l,n=o,t[n]==="]"&&n++}if(i&&s.type==="ArithConcat"&&(s={type:"ArithDynamicElement",nameExpr:s,subscript:i},i=void 0),n=_(t,n),s.type==="ArithConcat"||s.type==="ArithVariable"||s.type==="ArithDynamicElement"){for(let l of Re)if(t.slice(n,n+l.length)===l&&t.slice(n,n+l.length+1)!=="=="){n+=l.length;let{expr:o,pos:u}=ge(e,t,n);return s.type==="ArithDynamicElement"?{expr:{type:"ArithDynamicAssignment",operator:l,target:s.nameExpr,subscript:s.subscript,value:o},pos:u}:s.type==="ArithConcat"?{expr:{type:"ArithDynamicAssignment",operator:l,target:s,value:o},pos:u}:{expr:{type:"ArithAssignment",operator:l,variable:s.name,value:o},pos:u}}}if(t.slice(n,n+2)==="++"||t.slice(n,n+2)==="--"){let l=t.slice(n,n+2);return n+=2,{expr:{type:"ArithUnary",operator:l,operand:s,prefix:!1},pos:n}}return{expr:s,pos:n}}function Vt(e,t,r,s=!1){let n=_(t,r),a=Dt(G,e,t,n);if(a)return a;let i=vt(t,n);if(i)return i;let l=xt(t,n);if(l)return l;if(t.slice(n,n+2)==="$("&&t[n+2]!=="("){n+=2;let u=1,c=n;for(;n<t.length&&u>0;)t[n]==="("?u++:t[n]===")"&&u--,u>0&&n++;let f=t.slice(c,n);return n++,{expr:{type:"ArithCommandSubst",command:f},pos:n}}if(t[n]==="`"){n++;let u=n;for(;n<t.length&&t[n]!=="`";)n++;let c=t.slice(u,n);return t[n]==="`"&&n++,{expr:{type:"ArithCommandSubst",command:c},pos:n}}if(t[n]==="("){n++;let{expr:u,pos:c}=G(e,t,n);return n=_(t,c),t[n]===")"&&n++,{expr:{type:"ArithGroup",expression:u},pos:n}}if(t[n]==="'"){n++;let u="";for(;n<t.length&&t[n]!=="'";)u+=t[n],n++;t[n]==="'"&&n++;let c=Number.parseInt(u,10);return{expr:{type:"ArithSingleQuote",content:u,value:Number.isNaN(c)?0:c},pos:n}}if(t[n]==='"'){n++;let u="";for(;n<t.length&&t[n]!=='"';)t[n]==="\\"&&n+1<t.length?(u+=t[n+1],n+=2):(u+=t[n],n++);t[n]==='"'&&n++;let c=u.trim();if(!c)return{expr:{type:"ArithNumber",value:0},pos:n};let{expr:f}=G(e,c,0);return{expr:f,pos:n}}if(/[0-9]/.test(t[n])){let u="",c=!1,f=!1;for(;n<t.length;){let d=t[n];if(c)if(/[0-9a-zA-Z@_]/.test(d))u+=d,n++;else break;else if(d==="#")c=!0,u+=d,n++;else if(u==="0"&&(d==="x"||d==="X")&&n+1<t.length&&/[0-9a-fA-F]/.test(t[n+1]))f=!0,u+=d,n++;else if(f&&/[0-9a-fA-F]/.test(d))u+=d,n++;else if(!f&&/[0-9]/.test(d))u+=d,n++;else break}if(n<t.length&&/[a-zA-Z_]/.test(t[n])){let d=u;for(;n<t.length&&/[a-zA-Z0-9_]/.test(t[n]);)d+=t[n],n++;return{expr:{type:"ArithSyntaxError",errorToken:d,message:`${d}: value too great for base (error token is "${d}")`},pos:n}}if(t[n]==="."&&/[0-9]/.test(t[n+1]))throw new C(`${u}.${t[n+1]}...: syntax error: invalid arithmetic operator`);if(t[n]==="["){let d=t.slice(n).trim();return{expr:{type:"ArithNumberSubscript",number:u,errorToken:d},pos:t.length}}return{expr:{type:"ArithNumber",value:me(u)},pos:n}}if(t[n]==="$"&&t[n+1]==="{"){let u=n+2,c=1,f=u;for(;f<t.length&&c>0;)t[f]==="{"?c++:t[f]==="}"&&c--,c>0&&f++;let p=t.slice(u,f),d=f+1;if(t[d]==="#"){let g=d+1;for(;g<t.length&&/[0-9a-zA-Z@_]/.test(t[g]);)g++;let m=t.slice(d+1,g);return{expr:{type:"ArithDynamicBase",baseExpr:p,value:m},pos:g}}if(/[0-9]/.test(t[d])||t[d]==="x"||t[d]==="X"){let g=d;if(t[d]==="x"||t[d]==="X")for(g++;g<t.length&&/[0-9a-fA-F]/.test(t[g]);)g++;else for(;g<t.length&&/[0-9]/.test(t[g]);)g++;let m=t.slice(d,g);return{expr:{type:"ArithDynamicNumber",prefix:p,suffix:m},pos:g}}return n=d,{expr:{type:"ArithBracedExpansion",content:p},pos:n}}if(t[n]==="$"&&n+1<t.length&&/[0-9]/.test(t[n+1])){n++;let u="";for(;n<t.length&&/[0-9]/.test(t[n]);)u+=t[n],n++;return{expr:{type:"ArithVariable",name:u,hasDollarPrefix:!0},pos:n}}if(t[n]==="$"&&n+1<t.length&&/[*@#?\-!$]/.test(t[n+1])){let u=t[n+1];return n+=2,{expr:{type:"ArithSpecialVar",name:u},pos:n}}let o=!1;if(t[n]==="$"&&n+1<t.length&&/[a-zA-Z_]/.test(t[n+1])&&(o=!0,n++),n<t.length&&/[a-zA-Z_]/.test(t[n])){let u="";for(;n<t.length&&/[a-zA-Z0-9_]/.test(t[n]);)u+=t[n],n++;if(t[n]==="["&&!s){n++;let c;if(t[n]==="'"||t[n]==='"'){let p=t[n];for(n++,c="";n<t.length&&t[n]!==p;)c+=t[n],n++;t[n]===p&&n++,n=_(t,n),t[n]==="]"&&n++}let f;if(c===void 0){let{expr:p,pos:d}=G(e,t,n);f=p,n=d,t[n]==="]"&&n++}if(n=_(t,n),t[n]==="["&&f)return{expr:{type:"ArithDoubleSubscript",array:u,index:f},pos:n};if(!s){for(let p of Re)if(t.slice(n,n+p.length)===p&&t.slice(n,n+p.length+1)!=="=="){n+=p.length;let{expr:d,pos:g}=ge(e,t,n);return{expr:{type:"ArithAssignment",operator:p,variable:u,subscript:f,stringKey:c,value:d},pos:g}}}return{expr:{type:"ArithArrayElement",array:u,index:f,stringKey:c},pos:n}}if(n=_(t,n),!s){for(let c of Re)if(t.slice(n,n+c.length)===c&&t.slice(n,n+c.length+1)!=="=="){n+=c.length;let{expr:f,pos:p}=ge(e,t,n);return{expr:{type:"ArithAssignment",operator:c,variable:u,value:f},pos:p}}}return{expr:{type:"ArithVariable",name:u,hasDollarPrefix:o},pos:n}}if(t[n]==="#"){let u=n+1;for(;u<t.length&&t[u]!==`
|
|
5
|
+
`;)u++;let c=t.slice(n,u).trim()||"#";return{expr:{type:"ArithSyntaxError",errorToken:c,message:`${c}: syntax error: invalid arithmetic operator (error token is "${c}")`},pos:t.length}}return{expr:{type:"ArithNumber",value:0},pos:n}}var w={script(e){return{type:"Script",statements:e}},statement(e,t=[],r=!1,s,n){let a={type:"Statement",pipelines:e,operators:t,background:r};return s&&(a.deferredError=s),n!==void 0&&(a.sourceText=n),a},pipeline(e,t=!1,r=!1,s=!1,n){return{type:"Pipeline",commands:e,negated:t,timed:r,timePosix:s,pipeStderr:n}},simpleCommand(e,t=[],r=[],s=[]){return{type:"SimpleCommand",name:e,args:t,assignments:r,redirections:s}},word(e){return{type:"Word",parts:e}},literal(e){return{type:"Literal",value:e}},singleQuoted(e){return{type:"SingleQuoted",value:e}},doubleQuoted(e){return{type:"DoubleQuoted",parts:e}},escaped(e){return{type:"Escaped",value:e}},parameterExpansion(e,t=null){return{type:"ParameterExpansion",parameter:e,operation:t}},commandSubstitution(e,t=!1){return{type:"CommandSubstitution",body:e,legacy:t}},arithmeticExpansion(e){return{type:"ArithmeticExpansion",expression:e}},assignment(e,t,r=!1,s=null){return{type:"Assignment",name:e,value:t,append:r,array:s}},redirection(e,t,r=null,s){let n={type:"Redirection",fd:r,operator:e,target:t};return s&&(n.fdVariable=s),n},hereDoc(e,t,r=!1,s=!1){return{type:"HereDoc",delimiter:e,content:t,stripTabs:r,quoted:s}},ifNode(e,t=null,r=[]){return{type:"If",clauses:e,elseBody:t,redirections:r}},forNode(e,t,r,s=[]){return{type:"For",variable:e,words:t,body:r,redirections:s}},whileNode(e,t,r=[]){return{type:"While",condition:e,body:t,redirections:r}},untilNode(e,t,r=[]){return{type:"Until",condition:e,body:t,redirections:r}},caseNode(e,t,r=[]){return{type:"Case",word:e,items:t,redirections:r}},caseItem(e,t,r=";;"){return{type:"CaseItem",patterns:e,body:t,terminator:r}},subshell(e,t=[]){return{type:"Subshell",body:e,redirections:t}},group(e,t=[]){return{type:"Group",body:e,redirections:t}},functionDef(e,t,r=[],s){return{type:"FunctionDef",name:e,body:t,redirections:r,sourceFile:s}},conditionalCommand(e,t=[],r){return{type:"ConditionalCommand",expression:e,redirections:t,line:r}},arithmeticCommand(e,t=[],r){return{type:"ArithmeticCommand",expression:e,redirections:t,line:r}}};var h;(function(e){e.EOF="EOF",e.NEWLINE="NEWLINE",e.SEMICOLON="SEMICOLON",e.AMP="AMP",e.PIPE="PIPE",e.PIPE_AMP="PIPE_AMP",e.AND_AND="AND_AND",e.OR_OR="OR_OR",e.BANG="BANG",e.LESS="LESS",e.GREAT="GREAT",e.DLESS="DLESS",e.DGREAT="DGREAT",e.LESSAND="LESSAND",e.GREATAND="GREATAND",e.LESSGREAT="LESSGREAT",e.DLESSDASH="DLESSDASH",e.CLOBBER="CLOBBER",e.TLESS="TLESS",e.AND_GREAT="AND_GREAT",e.AND_DGREAT="AND_DGREAT",e.LPAREN="LPAREN",e.RPAREN="RPAREN",e.LBRACE="LBRACE",e.RBRACE="RBRACE",e.DSEMI="DSEMI",e.SEMI_AND="SEMI_AND",e.SEMI_SEMI_AND="SEMI_SEMI_AND",e.DBRACK_START="DBRACK_START",e.DBRACK_END="DBRACK_END",e.DPAREN_START="DPAREN_START",e.DPAREN_END="DPAREN_END",e.IF="IF",e.THEN="THEN",e.ELSE="ELSE",e.ELIF="ELIF",e.FI="FI",e.FOR="FOR",e.WHILE="WHILE",e.UNTIL="UNTIL",e.DO="DO",e.DONE="DONE",e.CASE="CASE",e.ESAC="ESAC",e.IN="IN",e.FUNCTION="FUNCTION",e.SELECT="SELECT",e.TIME="TIME",e.COPROC="COPROC",e.WORD="WORD",e.NAME="NAME",e.NUMBER="NUMBER",e.ASSIGNMENT_WORD="ASSIGNMENT_WORD",e.FD_VARIABLE="FD_VARIABLE",e.COMMENT="COMMENT",e.HEREDOC_CONTENT="HEREDOC_CONTENT"})(h||(h={}));var pe=class extends Error{line;column;constructor(t,r,s){super(`line ${r}: ${t}`),this.line=r,this.column=s,this.name="LexerError"}},Bt=new Map([["if",h.IF],["then",h.THEN],["else",h.ELSE],["elif",h.ELIF],["fi",h.FI],["for",h.FOR],["while",h.WHILE],["until",h.UNTIL],["do",h.DO],["done",h.DONE],["case",h.CASE],["esac",h.ESAC],["in",h.IN],["function",h.FUNCTION],["select",h.SELECT],["time",h.TIME],["coproc",h.COPROC]]);function Ft(e){let t=e.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);if(!t)return!1;let r=e.slice(t[0].length);if(r===""||r==="+")return!0;if(r[0]==="["){let s=0,n=0;for(;n<r.length;n++)if(r[n]==="[")s++;else if(r[n]==="]"&&(s--,s===0))break;if(s!==0||n>=r.length)return!1;let a=r.slice(n+1);return a===""||a==="+"}return!1}function Qt(e){let t=0;for(let r=0;r<e.length;r++){let s=e[r];if(s==="[")t++;else if(s==="]")t--;else{if(t===0&&s==="=")return r;if(t===0&&s==="+"&&e[r+1]==="=")return r+1}}return-1}var Dr=[[";",";","&",h.SEMI_SEMI_AND],["<","<","<",h.TLESS],["&",">",">",h.AND_DGREAT]],vr=[["[","[",h.DBRACK_START],["]","]",h.DBRACK_END],["(","(",h.DPAREN_START],[")",")",h.DPAREN_END],["&","&",h.AND_AND],["|","|",h.OR_OR],[";",";",h.DSEMI],[";","&",h.SEMI_AND],["|","&",h.PIPE_AMP],[">",">",h.DGREAT],["<","&",h.LESSAND],[">","&",h.GREATAND],["<",">",h.LESSGREAT],[">","|",h.CLOBBER],["&",">",h.AND_GREAT]],xr=new Map([["|",h.PIPE],["&",h.AMP],[";",h.SEMICOLON],["(",h.LPAREN],[")",h.RPAREN],["<",h.LESS],[">",h.GREAT]]);function $r(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)}function zt(e){return e===" "||e===" "||e===`
|
|
6
|
+
`||e===";"||e==="&"||e==="|"||e==="("||e===")"||e==="<"||e===">"}var De=class{input;pos=0;line=1;column=1;tokens=[];pendingHeredocs=[];dparenDepth=0;constructor(t){this.input=t}tokenize(){let r=this.input.length,s=this.tokens,n=this.pendingHeredocs;for(;this.pos<r;){if(n.length>0&&s.length>0&&s[s.length-1].type===h.NEWLINE){this.readHeredocContent();continue}if(this.skipWhitespace(),this.pos>=r)break;let a=this.nextToken();a&&s.push(a)}return s.push({type:h.EOF,value:"",start:this.pos,end:this.pos,line:this.line,column:this.column}),s}skipWhitespace(){let t=this.input,r=t.length,s=this.pos,n=this.column,a=this.line;for(;s<r;){let i=t[s];if(i===" "||i===" ")s++,n++;else if(i==="\\"&&t[s+1]===`
|
|
7
7
|
`)s+=2,a++,n=1;else break}this.pos=s,this.column=n,this.line=a}nextToken(){let t=this.input,r=this.pos,s=this.line,n=this.column,a=t[r],i=t[r+1],l=t[r+2];if(a==="#"&&this.dparenDepth===0)return this.readComment(r,s,n);if(a===`
|
|
8
8
|
`)return this.pos=r+1,this.line++,this.column=1,{type:h.NEWLINE,value:`
|
|
9
|
-
`,start:r,end:r+1,line:s,column:n};if(a==="<"&&i==="<"&&l==="-")return this.pos=r+3,this.column=n+3,this.registerHeredocFromLookahead(!0),this.makeToken(h.DLESSDASH,"<<-",r,s,n);for(let[u,c,f,p]of
|
|
10
|
-
`&&p!==";"&&p!=="&"&&p!=="|"&&p!=="("&&p!==")"&&p!=="<"&&p!==">")break}return this.pos=r+2,this.column=n+2,this.makeToken(f,u+c,r,s,n)}if(a==="("&&this.dparenDepth>0)return this.pos=r+1,this.column=n+1,this.dparenDepth++,this.makeToken(h.LPAREN,"(",r,s,n);if(a===")"&&this.dparenDepth>1)return this.pos=r+1,this.column=n+1,this.dparenDepth--,this.makeToken(h.RPAREN,")",r,s,n);let o=
|
|
9
|
+
`,start:r,end:r+1,line:s,column:n};if(a==="<"&&i==="<"&&l==="-")return this.pos=r+3,this.column=n+3,this.registerHeredocFromLookahead(!0),this.makeToken(h.DLESSDASH,"<<-",r,s,n);for(let[u,c,f,p]of Dr)if(a===u&&i===c&&l===f)return this.pos=r+3,this.column=n+3,this.makeToken(p,u+c+f,r,s,n);if(a==="<"&&i==="<")return this.pos=r+2,this.column=n+2,this.registerHeredocFromLookahead(!1),this.makeToken(h.DLESS,"<<",r,s,n);if(a==="("&&i==="(")return this.dparenDepth>0?(this.pos=r+1,this.column=n+1,this.dparenDepth++,this.makeToken(h.LPAREN,"(",r,s,n)):this.looksLikeNestedSubshells(r+2)||this.dparenClosesWithSpacedParens(r+2)?(this.pos=r+1,this.column=n+1,this.makeToken(h.LPAREN,"(",r,s,n)):(this.pos=r+2,this.column=n+2,this.dparenDepth=1,this.makeToken(h.DPAREN_START,"((",r,s,n));if(a===")"&&i===")")return this.dparenDepth===1?(this.pos=r+2,this.column=n+2,this.dparenDepth=0,this.makeToken(h.DPAREN_END,"))",r,s,n)):this.dparenDepth>1?(this.pos=r+1,this.column=n+1,this.dparenDepth--,this.makeToken(h.RPAREN,")",r,s,n)):(this.pos=r+1,this.column=n+1,this.makeToken(h.RPAREN,")",r,s,n));for(let[u,c,f]of vr)if(!(u==="("&&c==="("||u===")"&&c===")")&&!(this.dparenDepth>0&&u===";"&&(f===h.DSEMI||f===h.SEMI_AND||f===h.SEMI_SEMI_AND))&&a===u&&i===c){if(f===h.DBRACK_START||f===h.DBRACK_END){let p=t[r+2];if(p!==void 0&&p!==" "&&p!==" "&&p!==`
|
|
10
|
+
`&&p!==";"&&p!=="&"&&p!=="|"&&p!=="("&&p!==")"&&p!=="<"&&p!==">")break}return this.pos=r+2,this.column=n+2,this.makeToken(f,u+c,r,s,n)}if(a==="("&&this.dparenDepth>0)return this.pos=r+1,this.column=n+1,this.dparenDepth++,this.makeToken(h.LPAREN,"(",r,s,n);if(a===")"&&this.dparenDepth>1)return this.pos=r+1,this.column=n+1,this.dparenDepth--,this.makeToken(h.RPAREN,")",r,s,n);let o=xr.get(a);if(o!==void 0)return this.pos=r+1,this.column=n+1,this.makeToken(o,a,r,s,n);if(a==="{"){let u=this.scanFdVariable(r);return u!==null?(this.pos=u.end,this.column=n+(u.end-r),{type:h.FD_VARIABLE,value:u.varname,start:r,end:u.end,line:s,column:n}):i==="}"?(this.pos=r+2,this.column=n+2,{type:h.WORD,value:"{}",start:r,end:r+2,line:s,column:n,quoted:!1,singleQuoted:!1}):this.scanBraceExpansion(r)!==null?this.readWordWithBraceExpansion(r,s,n):this.scanLiteralBraceWord(r)!==null?this.readWordWithBraceExpansion(r,s,n):i!==void 0&&i!==" "&&i!==" "&&i!==`
|
|
11
11
|
`?this.readWord(r,s,n):(this.pos=r+1,this.column=n+1,this.makeToken(h.LBRACE,"{",r,s,n))}return a==="}"?this.isWordCharFollowing(r+1)?this.readWord(r,s,n):(this.pos=r+1,this.column=n+1,this.makeToken(h.RBRACE,"}",r,s,n)):a==="!"?i==="="?(this.pos=r+2,this.column=n+2,this.makeToken(h.WORD,"!=",r,s,n)):(this.pos=r+1,this.column=n+1,this.makeToken(h.BANG,"!",r,s,n)):this.readWord(r,s,n)}looksLikeNestedSubshells(t){let r=this.input,s=r.length,n=t;for(;n<s&&(r[n]===" "||r[n]===" ");)n++;if(n>=s)return!1;let a=r[n];if(a==="(")return this.looksLikeNestedSubshells(n+1);let i=/[a-zA-Z_]/.test(a),l=a==="!"||a==="[";if(!i&&!l)return!1;let o=n;for(;o<s&&/[a-zA-Z0-9_\-.]/.test(r[o]);)o++;if(o===n)return l;let u=o;for(;u<s&&(r[u]===" "||r[u]===" ");)u++;if(u>=s)return!1;let c=r[u];if(c==="="&&r[u+1]!=="="||c===`
|
|
12
12
|
`||o===u&&/[+\-*/%<>&|^!~?:]/.test(c)&&c!=="-"||c===")"&&r[u+1]===")")return!1;if(u>o&&(c==="-"||c==='"'||c==="'"||c==="$"||/[a-zA-Z_/.]/.test(c))){let f=u;for(;f<s&&r[f]!==`
|
|
13
13
|
`;){if(r[f]===")")return!0;f++}return!1}if(c===")"){let f=u+1;for(;f<s&&(r[f]===" "||r[f]===" ");)f++;if(r[f]==="|"&&r[f+1]==="|"||r[f]==="&"&&r[f+1]==="&"||r[f]===";"||r[f]==="|"&&r[f+1]!=="|")return!0}return!1}makeToken(t,r,s,n,a){return{type:t,value:r,start:s,end:this.pos,line:n,column:a}}readComment(t,r,s){let n=this.input,a=n.length,i=this.pos;for(;i<a&&n[i]!==`
|
|
14
14
|
`;)i++;let l=n.slice(t,i);return this.pos=i,this.column=s+(i-t),{type:h.COMMENT,value:l,start:t,end:i,line:r,column:s}}readWord(t,r,s){let n=this.input,a=n.length,i=this.pos,l=i;for(;i<a;){let y=n[i];if(y===" "||y===" "||y===`
|
|
15
15
|
`||y===";"||y==="&"||y==="|"||y==="("||y===")"||y==="<"||y===">"||y==="'"||y==='"'||y==="\\"||y==="$"||y==="`"||y==="{"||y==="}"||y==="~"||y==="*"||y==="?"||y==="[")break;i++}if(i>l){let y=n[i];if(!(y==="("&&i>l&&"@*+?!".includes(n[i-1]))){if(i>=a||y===" "||y===" "||y===`
|
|
16
|
-
`||y===";"||y==="&"||y==="|"||y==="("||y===")"||y==="<"||y===">"){let b=n.slice(l,i);this.pos=i,this.column=s+(i-l);let
|
|
16
|
+
`||y===";"||y==="&"||y==="|"||y==="("||y===")"||y==="<"||y===">"){let b=n.slice(l,i);this.pos=i,this.column=s+(i-l);let v=Bt.get(b);if(v!==void 0)return{type:v,value:b,start:t,end:i,line:r,column:s};let Z=Qt(b);return Z>0&&Ft(b.slice(0,Z))?{type:h.ASSIGNMENT_WORD,value:b,start:t,end:i,line:r,column:s}:/^[0-9]+$/.test(b)?{type:h.NUMBER,value:b,start:t,end:i,line:r,column:s}:/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(b)?{type:h.NAME,value:b,start:t,end:i,line:r,column:s,quoted:!1,singleQuoted:!1}:{type:h.WORD,value:b,start:t,end:i,line:r,column:s,quoted:!1,singleQuoted:!1}}}}i=this.pos;let o=this.column,u=this.line,c="",f=!1,p=!1,d=!1,g=!1,m=n[i]==='"'||n[i]==="'",E=!1,A=0;for(;i<a;){let y=n[i];if(!d&&!g){if(y==="("&&c.length>0&&"@*+?!".includes(c[c.length-1])){let b=this.scanExtglobPattern(i);if(b!==null){c+=b.content,i=b.end,o+=b.content.length;continue}}if(y==="["&&A===0){if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(c)){let b=i+1<a?n[i+1]:"";if(b==="^"||b==="!"){c+=y,i++,o++;continue}A=1,c+=y,i++,o++;continue}}else if(y==="["&&A>0){c.length>0&&c[c.length-1]!=="\\"&&A++,c+=y,i++,o++;continue}else if(y==="]"&&A>0){c.length>0&&c[c.length-1]!=="\\"&&A--,c+=y,i++,o++;continue}if(A>0){if(y===`
|
|
17
17
|
`)break;c+=y,i++,o++;continue}if(y===" "||y===" "||y===`
|
|
18
|
-
`||y===";"||y==="&"||y==="|"||y==="("||y===")"||y==="<"||y===">")break}if(y==="$"&&i+1<a&&n[i+1]==="'"&&!d&&!g){for(c+="$'",i+=2,o+=2;i<a&&n[i]!=="'";)n[i]==="\\"&&i+1<a?(c+=n[i]+n[i+1],i+=2,o+=2):(c+=n[i],i++,o++);i<a&&(c+="'",i++,o++);continue}if(y==="$"&&i+1<a&&n[i+1]==='"'&&!d&&!g){i++,o++,g=!0,f=!0,c===""&&(m=!0),i++,o++;continue}if(y==="'"&&!g){if(d)if(d=!1,!m||E)c+=y;else{let b=i+1<a?n[i+1]:"";b&&!
|
|
18
|
+
`||y===";"||y==="&"||y==="|"||y==="("||y===")"||y==="<"||y===">")break}if(y==="$"&&i+1<a&&n[i+1]==="'"&&!d&&!g){for(c+="$'",i+=2,o+=2;i<a&&n[i]!=="'";)n[i]==="\\"&&i+1<a?(c+=n[i]+n[i+1],i+=2,o+=2):(c+=n[i],i++,o++);i<a&&(c+="'",i++,o++);continue}if(y==="$"&&i+1<a&&n[i+1]==='"'&&!d&&!g){i++,o++,g=!0,f=!0,c===""&&(m=!0),i++,o++;continue}if(y==="'"&&!g){if(d)if(d=!1,!m||E)c+=y;else{let b=i+1<a?n[i+1]:"";b&&!zt(b)&&b!=="'"&&(b==='"'?(E=!0,c+=y,p=!1,f=!1):(E=!0,c+=y))}else d=!0,m&&!E?(p=!0,f=!0):c+=y;i++,o++;continue}if(y==='"'&&!d){if(g)if(g=!1,!m||E)c+=y;else{let b=i+1<a?n[i+1]:"";b&&!zt(b)&&b!=='"'&&(b==="'"?(E=!0,c+=y,p=!1,f=!1):(E=!0,c+=y))}else g=!0,m&&!E?f=!0:c+=y;i++,o++;continue}if(y==="\\"&&!d&&i+1<a){let b=n[i+1];if(b===`
|
|
19
19
|
`){i+=2,u++,o=1;continue}if(g){if(b==='"'||b==="\\"||b==="$"||b==="`"||b===`
|
|
20
20
|
`){if(b===`
|
|
21
|
-
`){i+=2,o=1,u++;continue}c+=y+b,i+=2,o+=2;continue}}else{b==="\\"||b==='"'||b==="'"||b==="`"||b==="*"||b==="?"||b==="["||b==="]"||b==="("||b===")"||b==="$"||b==="-"||b==="."||b==="^"||b==="+"||b==="{"||b==="}"?c+=y+b:c+=b,i+=2,o+=2;continue}}if(y==="$"&&i+1<a&&n[i+1]==="("&&!d){c+=y,i++,o++,c+=n[i],i++,o++;let b=1,
|
|
21
|
+
`){i+=2,o=1,u++;continue}c+=y+b,i+=2,o+=2;continue}}else{b==="\\"||b==='"'||b==="'"||b==="`"||b==="*"||b==="?"||b==="["||b==="]"||b==="("||b===")"||b==="$"||b==="-"||b==="."||b==="^"||b==="+"||b==="{"||b==="}"?c+=y+b:c+=b,i+=2,o+=2;continue}}if(y==="$"&&i+1<a&&n[i+1]==="("&&!d){c+=y,i++,o++,c+=n[i],i++,o++;let b=1,v=!1,Z=!1,ie=0,J=!1,q="",Ne=n[i]==="("&&!this.dollarDparenIsSubshell(i);for(;b>0&&i<a;){let $=n[i];if(c+=$,v)$==="'"&&(v=!1);else if(Z)$==="\\"&&i+1<a?(c+=n[i+1],i++,o++):$==='"'&&(Z=!1);else if($==="'")v=!0,q="";else if($==='"')Z=!0,q="";else if($==="\\"&&i+1<a)c+=n[i+1],i++,o++,q="";else if($==="$"&&i+1<a&&n[i+1]==="{"){i++,o++,c+=n[i],i++,o++;let Be=1,ke=!1,Fe=!1;for(;Be>0&&i<a;){let Y=n[i];if(Y==="\\"&&i+1<a&&!ke){c+=Y,i++,o++,c+=n[i],i++,o++;continue}c+=Y,ke?Y==="'"&&(ke=!1):Fe?Y==='"'&&(Fe=!1):Y==="'"?ke=!0:Y==='"'?Fe=!0:Y==="{"?Be++:Y==="}"&&Be--,Y===`
|
|
22
22
|
`?(u++,o=0):o++,i++}q="";continue}else if($==="#"&&!Ne&&(q===""||/\s/.test(n[i-1]||""))){for(;i+1<a&&n[i+1]!==`
|
|
23
23
|
`;)i++,o++,c+=n[i];q=""}else/[a-zA-Z_]/.test($)?q+=$:(q==="case"?(ie++,J=!1):q==="in"&&ie>0?J=!0:q==="esac"&&ie>0&&(ie--,J=!1),q="",$==="("?i>0&&n[i-1]==="$"?b++:J||b++:$===")"?J?J=!1:b--:$===";"&&ie>0&&i+1<a&&n[i+1]===";"&&(J=!0));$===`
|
|
24
|
-
`&&(u++,o=0,q=""),i++,o++}continue}if(y==="$"&&i+1<a&&n[i+1]==="["&&!d){c+=y,i++,o++,c+=n[i],i++,o++;let b=1;for(;b>0&&i<a;){let
|
|
25
|
-
`&&(u++,o=0),i++,o++}continue}if(y==="$"&&i+1<a&&n[i+1]==="{"&&!d){c+=y,i++,o++,c+=n[i],i++,o++;let b=1,
|
|
26
|
-
`){i+=2,u++,o=1;continue}if($==="\\"&&i+1<a&&!
|
|
27
|
-
`&&(u++,o=0),i++,o++}if(
|
|
24
|
+
`&&(u++,o=0,q=""),i++,o++}continue}if(y==="$"&&i+1<a&&n[i+1]==="["&&!d){c+=y,i++,o++,c+=n[i],i++,o++;let b=1;for(;b>0&&i<a;){let v=n[i];c+=v,v==="["?b++:v==="]"?b--:v===`
|
|
25
|
+
`&&(u++,o=0),i++,o++}continue}if(y==="$"&&i+1<a&&n[i+1]==="{"&&!d){c+=y,i++,o++,c+=n[i],i++,o++;let b=1,v=!1,Z=!1,ie=u,J=o,q=u,Ne=o;for(;b>0&&i<a;){let $=n[i];if($==="\\"&&i+1<a&&n[i+1]===`
|
|
26
|
+
`){i+=2,u++,o=1;continue}if($==="\\"&&i+1<a&&!v){c+=$,i++,o++,c+=n[i],i++,o++;continue}c+=$,v?$==="'"&&(v=!1):Z?$==='"'&&(Z=!1):$==="'"?(v=!0,ie=u,J=o):$==='"'?(Z=!0,q=u,Ne=o):$==="{"?b++:$==="}"&&b--,$===`
|
|
27
|
+
`&&(u++,o=0),i++,o++}if(v)throw new pe("unexpected EOF while looking for matching `''",ie,J);if(Z)throw new pe("unexpected EOF while looking for matching `\"'",q,Ne);continue}if(y==="$"&&i+1<a&&!d){let b=n[i+1];if(b==="#"||b==="?"||b==="$"||b==="!"||b==="@"||b==="*"||b==="-"||b>="0"&&b<="9"){c+=y+b,i+=2,o+=2;continue}}if(y==="`"&&!d){for(c+=y,i++,o++;i<a&&n[i]!=="`";){let b=n[i];c+=b,b==="\\"&&i+1<a&&(c+=n[i+1],i++,o++),b===`
|
|
28
28
|
`&&(u++,o=0),i++,o++}i<a&&(c+=n[i],i++,o++);continue}c+=y,i++,y===`
|
|
29
|
-
`?(u++,o=1):o++}if(this.pos=i,this.column=o,this.line=u,E&&m&&(c=n[t]+c,f=!1,p=!1),d||g){let y=d?"'":'"';throw new pe(`unexpected EOF while looking for matching \`${y}'`,r,s)}if(!m&&c.length>=2){if(c[0]==="'"&&c[c.length-1]==="'"){let y=c.slice(1,-1);!y.includes("'")&&!y.includes('"')&&(c=y,f=!0,p=!0)}else if(c[0]==='"'&&c[c.length-1]==='"'){let y=c.slice(1,-1),b=!1;for(let
|
|
29
|
+
`?(u++,o=1):o++}if(this.pos=i,this.column=o,this.line=u,E&&m&&(c=n[t]+c,f=!1,p=!1),d||g){let y=d?"'":'"';throw new pe(`unexpected EOF while looking for matching \`${y}'`,r,s)}if(!m&&c.length>=2){if(c[0]==="'"&&c[c.length-1]==="'"){let y=c.slice(1,-1);!y.includes("'")&&!y.includes('"')&&(c=y,f=!0,p=!0)}else if(c[0]==='"'&&c[c.length-1]==='"'){let y=c.slice(1,-1),b=!1;for(let v=0;v<y.length;v++){if(y[v]==='"'){b=!0;break}y[v]==="\\"&&v+1<y.length&&v++}b||(c=y,f=!0,p=!1)}}if(c==="")return{type:h.WORD,value:"",start:t,end:i,line:r,column:s,quoted:f,singleQuoted:p};let S=Bt.get(c);if(!f&&S!==void 0)return{type:S,value:c,start:t,end:i,line:r,column:s};if(!m){let y=Qt(c);if(y>0&&Ft(c.slice(0,y)))return{type:h.ASSIGNMENT_WORD,value:c,start:t,end:i,line:r,column:s,quoted:f,singleQuoted:p}}return/^[0-9]+$/.test(c)?{type:h.NUMBER,value:c,start:t,end:i,line:r,column:s}:$r(c)?{type:h.NAME,value:c,start:t,end:i,line:r,column:s,quoted:f,singleQuoted:p}:{type:h.WORD,value:c,start:t,end:i,line:r,column:s,quoted:f,singleQuoted:p}}readHeredocContent(){for(;this.pendingHeredocs.length>0;){let t=this.pendingHeredocs.shift();if(!t)break;let r=this.pos,s=this.line,n=this.column,a="";for(;this.pos<this.input.length;){let i=this.pos,l="";for(;this.pos<this.input.length&&this.input[this.pos]!==`
|
|
30
30
|
`;)l+=this.input[this.pos],this.pos++,this.column++;if((t.stripTabs?l.replace(/^\t+/,""):l)===t.delimiter){this.pos<this.input.length&&this.input[this.pos]===`
|
|
31
31
|
`&&(this.pos++,this.line++,this.column=1);break}if(a+=l,a.length>10485760)throw new pe("Heredoc size limit exceeded (10485760 bytes)",s,n);this.pos<this.input.length&&this.input[this.pos]===`
|
|
32
32
|
`&&(a+=`
|
|
@@ -40,35 +40,35 @@ import{e as H,f as j,g as C,h as re,i as Pe,j as Rt,k as B}from"./chunk-K5IXNHO5
|
|
|
40
40
|
`&&(o=!0),n++;continue}if(u==="'"){i=!0,n++;continue}if(u==='"'){l=!0,n++;continue}if(u==="\\"){n+=2;continue}if(u===`
|
|
41
41
|
`&&(o=!0),u==="("){a++,n++;continue}if(u===")"){if(a--,a===1){let c=n+1;if(c<s&&r[c]===")")return!1;let f=c,p=!1;for(;f<s&&(r[f]===" "||r[f]===" "||r[f]===`
|
|
42
42
|
`);)p=!0,f++;if(p&&f<s&&r[f]===")"||o)return!0}if(a===0)return!1;n++;continue}n++}return!1}dparenClosesWithSpacedParens(t){let r=this.input,s=r.length,n=t,a=2,i=!1,l=!1;for(;n<s&&a>0;){let o=r[n];if(i){o==="'"&&(i=!1),n++;continue}if(l){if(o==="\\"){n+=2;continue}o==='"'&&(l=!1),n++;continue}if(o==="'"){i=!0,n++;continue}if(o==='"'){l=!0,n++;continue}if(o==="\\"){n+=2;continue}if(o==="("){a++,n++;continue}if(o===")"){if(a--,a===1){let u=n+1;if(u<s&&r[u]===")")return!1;let c=u,f=!1;for(;c<s&&(r[c]===" "||r[c]===" "||r[c]===`
|
|
43
|
-
`);)f=!0,c++;if(f&&c<s&&r[c]===")")return!0}if(a===0)return!1;n++;continue}if(a===1&&(o==="|"&&n+1<s&&r[n+1]==="|"||o==="&"&&n+1<s&&r[n+1]==="&"||o==="|"&&n+1<s&&r[n+1]!=="|"))return!0;n++}return!1}};var Ze=1e6,Ge=1e5,
|
|
44
|
-
`,n+=2;break;case"t":s+=" ",n+=2;break;case"r":s+="\r",n+=2;break;case"\\":s+="\\",n+=2;break;case"'":s+="'",n+=2;break;case'"':s+='"',n+=2;break;case"a":s+="\x07",n+=2;break;case"b":s+="\b",n+=2;break;case"e":case"E":s+="\x1B",n+=2;break;case"f":s+="\f",n+=2;break;case"v":s+="\v",n+=2;break;case"x":{let l=[],o=n;for(;o+1<t.length&&t[o]==="\\"&&t[o+1]==="x";){let u=t.slice(o+2,o+4),c=parseInt(u,16);if(!Number.isNaN(c)&&u.length>0)l.push(c),o+=2+u.length;else break}l.length>0?(s+=$r(l),n=o):(s+="\\x",n+=2);break}case"u":{let l=t.slice(n+2,n+6),o=parseInt(l,16);Number.isNaN(o)?(s+="\\u",n+=2):(s+=String.fromCharCode(o),n+=6);break}case"c":{if(n+2<t.length){let o=t[n+2].charCodeAt(0)&31;s+=String.fromCharCode(o),n+=3}else s+="\\c",n+=2;break}case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":{let l="",o=n+1;for(;o<t.length&&o<n+4&&/[0-7]/.test(t[o]);)l+=t[o],o++;let u=parseInt(l,8);s+=String.fromCharCode(u),n=o;break}default:s+=a,n++}else s+=a,n++}return n<t.length&&t[n]==="'"&&n++,{part:w.literal(s),endIndex:n}}function He(e,t){let r=t.trim();return r===""?{type:"ArithmeticExpression",expression:{type:"ArithNumber",value:0}}:T(e,r)}function Ht(e){let t=[],r="",s=0;for(let n=0;n<e.length;n++){let a=e[n];a==="{"?(s++,r+=a):a==="}"?(s--,r+=a):a===","&&s===0?(t.push(r),r=""):r+=a}return t.push(r),t}function Yt(e,t,r,s){let n=Ue(e,t,r,"{","}");if(n===-1)return null;let a=t.slice(r+1,n),i=a.match(/^(-?\d+)\.\.(-?\d+)(?:\.\.(-?\d+))?$/);if(i)return{part:{type:"BraceExpansion",items:[{type:"Range",start:Number.parseInt(i[1],10),end:Number.parseInt(i[2],10),step:i[3]?Number.parseInt(i[3],10):void 0,startStr:i[1],endStr:i[2]}]},endIndex:n+1};let l=a.match(/^([a-zA-Z])\.\.([a-zA-Z])(?:\.\.(-?\d+))?$/);return l?{part:{type:"BraceExpansion",items:[{type:"Range",start:l[1],end:l[2],step:l[3]?Number.parseInt(l[3],10):void 0}]},endIndex:n+1}:a.includes(",")&&s?{part:{type:"BraceExpansion",items:Ht(a).map(c=>({type:"Word",word:w.word(s(e,c,!1,!1,!1))}))},endIndex:n+1}:a.includes(",")?{part:{type:"BraceExpansion",items:Ht(a).map(c=>({type:"Word",word:w.word([w.literal(c)])}))},endIndex:n+1}:null}function je(e,t){let r="";for(let s of t.parts)switch(s.type){case"Literal":r+=s.value;break;case"SingleQuoted":r+=`'${s.value}'`;break;case"Escaped":r+=s.value;break;case"DoubleQuoted":r+='"';for(let n of s.parts)n.type==="Literal"||n.type==="Escaped"?r+=n.value:n.type==="ParameterExpansion"&&(r+=`\${${n.parameter}}`);r+='"';break;case"ParameterExpansion":r+=`\${${s.parameter}}`;break;case"Glob":r+=s.pattern;break;case"TildeExpansion":r+="~",s.user&&(r+=s.user);break;case"BraceExpansion":{r+="{";let n=[];for(let a of s.items)if(a.type==="Range"){let i=a.startStr??String(a.start),l=a.endStr??String(a.end);a.step!==void 0?n.push(`${i}..${l}..${a.step}`):n.push(`${i}..${l}`)}else n.push(je(e,a.word));n.length===1&&s.items[0].type==="Range"?r+=n[0]:r+=n.join(","),r+="}";break}default:r+=s.type}return r}function en(e,t){return{[h.LESS]:"<",[h.GREAT]:">",[h.DGREAT]:">>",[h.LESSAND]:"<&",[h.GREATAND]:">&",[h.LESSGREAT]:"<>",[h.CLOBBER]:">|",[h.TLESS]:"<<<",[h.AND_GREAT]:"&>",[h.AND_DGREAT]:"&>>",[h.DLESS]:"<",[h.DLESSDASH]:"<"}[t]||">"}function De(e){let t=e.current(),r=t.type;if(r===h.NUMBER){let s=e.peek(1);return t.end!==s.start?!1:Gt.has(s.type)}if(r===h.FD_VARIABLE){let s=e.peek(1);return Ut.has(s.type)}return Zt.has(r)}function xe(e){let t=null,r;e.check(h.NUMBER)?t=Number.parseInt(e.advance().value,10):e.check(h.FD_VARIABLE)&&(r=e.advance().value);let s=e.advance(),n=en(e,s.type);if(s.type===h.DLESS||s.type===h.DLESSDASH)return Cr(e,n,t,s.type===h.DLESSDASH);e.isWord()||e.error("Expected redirection target");let a=e.parseWord();return w.redirection(n,a,t,r)}function Cr(e,t,r,s){e.isWord()||e.error("Expected here-document delimiter");let n=e.advance(),a=n.value,i=n.quoted||!1;(a.startsWith("'")&&a.endsWith("'")||a.startsWith('"')&&a.endsWith('"'))&&(a=a.slice(1,-1));let l=w.redirection(s?"<<-":"<<",w.hereDoc(a,w.word([]),s,i),r);return e.addPendingHeredoc(l,a,s,i),l}function nn(e){let t=e.current().line,r=[],s=null,n=[],a=[];for(;e.check(h.ASSIGNMENT_WORD)||De(e);)e.checkIterationLimit(),e.check(h.ASSIGNMENT_WORD)?r.push(Or(e)):a.push(xe(e));if(e.isWord())s=e.parseWord();else if(r.length>0&&(e.check(h.DBRACK_START)||e.check(h.DPAREN_START))){let l=e.advance();s=w.word([w.literal(l.value)])}for(;(!e.isStatementEnd()||e.check(h.RBRACE))&&!e.check(h.PIPE,h.PIPE_AMP);)if(e.checkIterationLimit(),De(e))a.push(xe(e));else if(e.check(h.RBRACE)){let l=e.advance();n.push(e.parseWordFromString(l.value,!1,!1))}else if(e.check(h.LBRACE)){let l=e.advance();n.push(e.parseWordFromString(l.value,!1,!1))}else if(e.check(h.DBRACK_END)){let l=e.advance();n.push(e.parseWordFromString(l.value,!1,!1))}else if(e.isWord())n.push(e.parseWord());else if(e.check(h.ASSIGNMENT_WORD)){let l=e.advance(),o=l.value,u=o.endsWith("="),c=o.endsWith("=(");if((u||c)&&(c||e.check(h.LPAREN))){let f=c?o.slice(0,-2):o.slice(0,-1);c||e.expect(h.LPAREN);let p=Ke(e);e.expect(h.RPAREN);let d=p.map(m=>je(e,m)),g=`${f}=(${d.join(" ")})`;n.push(e.parseWordFromString(g,!1,!1))}else n.push(e.parseWordFromString(o,l.quoted,l.singleQuoted))}else if(e.check(h.LPAREN))e.error("syntax error near unexpected token `('");else break;let i=w.simpleCommand(s,n,r,a);return i.line=t,i}function Or(e){let t=e.expect(h.ASSIGNMENT_WORD),r=t.value,s=r.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);s||e.error(`Invalid assignment: ${r}`);let n=s[0],a,i=n.length;if(r[i]==="["){let f=0,p=i+1;for(;i<r.length;i++)if(r[i]==="[")f++;else if(r[i]==="]"&&(f--,f===0))break;f!==0&&e.error(`Invalid assignment: ${r}`),a=r.slice(p,i),i++}let l=r[i]==="+";l&&i++,r[i]!=="="&&e.error(`Invalid assignment: ${r}`),i++;let o=r.slice(i);if(o==="("){let f=Ke(e);e.expect(h.RPAREN);let p=a!==void 0?`${n}[${a}]`:n;return w.assignment(p,null,l,f)}if(o===""&&e.check(h.LPAREN)){let f=e.current();if(t.end===f.start){e.advance();let p=Ke(e);e.expect(h.RPAREN);let d=a!==void 0?`${n}[${a}]`:n;return w.assignment(d,null,l,p)}}let u=o?e.parseWordFromString(o,t.quoted,t.singleQuoted,!0):null,c=a!==void 0?`${n}[${a}]`:n;return w.assignment(c,u,l,null)}var Lr=new Set([h.AMP,h.PIPE,h.PIPE_AMP,h.SEMICOLON,h.AND_AND,h.OR_OR,h.DSEMI,h.SEMI_AND,h.SEMI_SEMI_AND]);function Ke(e){let t=[];for(e.skipNewlines();!e.check(h.RPAREN,h.EOF);)e.checkIterationLimit(),e.isWord()?t.push(e.parseWord()):Lr.has(e.current().type)?e.error(`syntax error near unexpected token \`${e.current().value}'`):e.advance(),e.skipNewlines();return t}function Xe(e,t){e.expect(h.IF);let r=[],s=e.parseCompoundList();e.expect(h.THEN);let n=e.parseCompoundList();if(n.length===0){let l=e.check(h.FI)?"fi":e.check(h.ELSE)?"else":e.check(h.ELIF)?"elif":"fi";e.error(`syntax error near unexpected token \`${l}'`)}for(r.push({condition:s,body:n});e.check(h.ELIF);){e.advance();let l=e.parseCompoundList();e.expect(h.THEN);let o=e.parseCompoundList();if(o.length===0){let u=e.check(h.FI)?"fi":e.check(h.ELSE)?"else":e.check(h.ELIF)?"elif":"fi";e.error(`syntax error near unexpected token \`${u}'`)}r.push({condition:l,body:o})}let a=null;e.check(h.ELSE)&&(e.advance(),a=e.parseCompoundList(),a.length===0&&e.error("syntax error near unexpected token `fi'")),e.expect(h.FI);let i=t?.skipRedirections?[]:e.parseOptionalRedirections();return w.ifNode(r,a,i)}function Je(e,t){let r=e.expect(h.FOR);if(e.check(h.DPAREN_START))return Tr(e,t,r.line);e.isWord()||e.error("Expected variable name in for loop");let n=e.advance().value,a=null;if(e.skipNewlines(),e.check(h.IN))for(e.advance(),a=[];!e.check(h.SEMICOLON,h.NEWLINE,h.DO,h.EOF)&&e.isWord();)a.push(e.parseWord());e.check(h.SEMICOLON)&&e.advance(),e.skipNewlines(),e.expect(h.DO);let i=e.parseCompoundList();e.expect(h.DONE);let l=t?.skipRedirections?[]:e.parseOptionalRedirections();return w.forNode(n,a,i,l)}function Tr(e,t,r){e.expect(h.DPAREN_START);let s=null,n=null,a=null,i=["","",""],l=0,o=0;for(;!e.check(h.DPAREN_END,h.EOF);){let f=e.advance();if(f.type===h.SEMICOLON&&o===0){if(l++,l>2)break}else f.value==="("&&o++,f.value===")"&&o--,i[l]+=f.value}e.expect(h.DPAREN_END),i[0].trim()&&(s=T(e,i[0].trim())),i[1].trim()&&(n=T(e,i[1].trim())),i[2].trim()&&(a=T(e,i[2].trim())),e.skipNewlines(),e.check(h.SEMICOLON)&&e.advance(),e.skipNewlines();let u;e.check(h.LBRACE)?(e.advance(),u=e.parseCompoundList(),e.expect(h.RBRACE)):(e.expect(h.DO),u=e.parseCompoundList(),e.expect(h.DONE));let c=t?.skipRedirections?[]:e.parseOptionalRedirections();return{type:"CStyleFor",init:s,condition:n,update:a,body:u,redirections:c,line:r}}function Ye(e,t){e.expect(h.WHILE);let r=e.parseCompoundList();e.expect(h.DO);let s=e.parseCompoundList();s.length===0&&e.error("syntax error near unexpected token `done'"),e.expect(h.DONE);let n=t?.skipRedirections?[]:e.parseOptionalRedirections();return w.whileNode(r,s,n)}function et(e,t){e.expect(h.UNTIL);let r=e.parseCompoundList();e.expect(h.DO);let s=e.parseCompoundList();s.length===0&&e.error("syntax error near unexpected token `done'"),e.expect(h.DONE);let n=t?.skipRedirections?[]:e.parseOptionalRedirections();return w.untilNode(r,s,n)}function tt(e,t){e.expect(h.CASE),e.isWord()||e.error("Expected word after 'case'");let r=e.parseWord();e.skipNewlines(),e.expect(h.IN),e.skipNewlines();let s=[];for(;!e.check(h.ESAC,h.EOF);){e.checkIterationLimit();let a=e.getPos(),i=Mr(e);if(i&&s.push(i),e.skipNewlines(),e.getPos()===a&&!i)break}e.expect(h.ESAC);let n=t?.skipRedirections?[]:e.parseOptionalRedirections();return w.caseNode(r,s,n)}function Mr(e){e.check(h.LPAREN)&&e.advance();let t=[];for(;e.isWord()&&(t.push(e.parseWord()),e.check(h.PIPE));)e.advance();if(t.length===0)return null;e.expect(h.RPAREN),e.skipNewlines();let r=[];for(;!e.check(h.DSEMI,h.SEMI_AND,h.SEMI_SEMI_AND,h.ESAC,h.EOF);){e.checkIterationLimit(),e.isWord()&&e.peek(1).type===h.RPAREN&&e.error("syntax error near unexpected token `)'"),e.check(h.LPAREN)&&e.peek(1).type===h.WORD&&e.error(`syntax error near unexpected token \`${e.peek(1).value}'`);let n=e.getPos(),a=e.parseStatement();if(a&&r.push(a),e.skipSeparators(!1),e.getPos()===n&&!a)break}let s=";;";return e.check(h.DSEMI)?(e.advance(),s=";;"):e.check(h.SEMI_AND)?(e.advance(),s=";&"):e.check(h.SEMI_SEMI_AND)&&(e.advance(),s=";;&"),w.caseItem(t,r,s)}function nt(e,t){e.expect(h.LPAREN);let r=e.parseCompoundList();e.expect(h.RPAREN);let s=t?.skipRedirections?[]:e.parseOptionalRedirections();return w.subshell(r,s)}function rt(e,t){e.expect(h.LBRACE);let r=e.parseCompoundList();e.expect(h.RBRACE);let s=t?.skipRedirections?[]:e.parseOptionalRedirections();return w.group(r,s)}var qr=["-a","-b","-c","-d","-e","-f","-g","-h","-k","-p","-r","-s","-t","-u","-w","-x","-G","-L","-N","-O","-S","-z","-n","-o","-v","-R"],Br=["==","!=","=~","<",">","-eq","-ne","-lt","-le","-gt","-ge","-nt","-ot","-ef"];function rn(e){return e.isWord()||e.check(h.LBRACE)||e.check(h.RBRACE)||e.check(h.ASSIGNMENT_WORD)}function sn(e){if(e.check(h.BANG)&&e.peek(1).type===h.LPAREN){e.advance(),e.advance();let t=1,r="!(";for(;t>0&&!e.check(h.EOF);)if(e.check(h.LPAREN))t++,r+="(",e.advance();else if(e.check(h.RPAREN))t--,t>0&&(r+=")"),e.advance();else if(e.isWord())r+=e.advance().value;else if(e.check(h.PIPE))r+="|",e.advance();else break;return r+=")",e.parseWordFromString(r,!1,!1,!1,!1,!0)}return e.parseWordNoBraceExpansion()}function it(e){return e.skipNewlines(),Fr(e)}function Fr(e){let t=an(e);for(e.skipNewlines();e.check(h.OR_OR);){e.advance(),e.skipNewlines();let r=an(e);t={type:"CondOr",left:t,right:r},e.skipNewlines()}return t}function an(e){let t=st(e);for(e.skipNewlines();e.check(h.AND_AND);){e.advance(),e.skipNewlines();let r=st(e);t={type:"CondAnd",left:t,right:r},e.skipNewlines()}return t}function st(e){return e.skipNewlines(),e.check(h.BANG)?(e.advance(),e.skipNewlines(),{type:"CondNot",operand:st(e)}):Qr(e)}function Qr(e){if(e.check(h.LPAREN)){e.advance();let t=it(e);return e.expect(h.RPAREN),{type:"CondGroup",expression:t}}if(rn(e)){let t=e.current(),r=t.value;if(qr.includes(r)&&!t.quoted){if(e.advance(),e.check(h.DBRACK_END)&&e.error(`Expected operand after ${r}`),rn(e)){let a=e.parseWordNoBraceExpansion();return{type:"CondUnary",operator:r,operand:a}}let n=e.current();e.error(`unexpected argument \`${n.value}' to conditional unary operator`)}let s=e.parseWordNoBraceExpansion();if(e.isWord()&&Br.includes(e.current().value)){let n=e.advance().value,a;return n==="=~"?a=zr(e):n==="=="||n==="!="?a=sn(e):a=e.parseWordNoBraceExpansion(),{type:"CondBinary",operator:n,left:s,right:a}}if(e.check(h.LESS)){e.advance();let n=e.parseWordNoBraceExpansion();return{type:"CondBinary",operator:"<",left:s,right:n}}if(e.check(h.GREAT)){e.advance();let n=e.parseWordNoBraceExpansion();return{type:"CondBinary",operator:">",left:s,right:n}}if(e.isWord()&&e.current().value==="="){e.advance();let n=sn(e);return{type:"CondBinary",operator:"==",left:s,right:n}}return{type:"CondWord",word:s}}e.error("Expected conditional expression")}function zr(e){let t=[],r=0,s=-1,n=e.getInput(),a=()=>e.check(h.DBRACK_END)||e.check(h.AND_AND)||e.check(h.OR_OR)||e.check(h.NEWLINE)||e.check(h.EOF);for(;!a();){let i=e.current(),l=s>=0&&i.start>s;if(r===0&&l)break;if(r>0&&l){let o=n.slice(s,i.start);t.push({type:"Literal",value:o})}if(e.isWord()||e.check(h.ASSIGNMENT_WORD)){let o=e.parseWordForRegex();t.push(...o.parts),s=e.peek(-1).end}else if(e.check(h.LPAREN)){let o=e.advance();t.push({type:"Literal",value:"("}),r++,s=o.end}else if(e.check(h.DPAREN_START)){let o=e.advance();t.push({type:"Literal",value:"(("}),r+=2,s=o.end}else if(e.check(h.DPAREN_END))if(r>=2){let o=e.advance();t.push({type:"Literal",value:"))"}),r-=2,s=o.end}else{if(r===1)break;break}else if(e.check(h.RPAREN))if(r>0){let o=e.advance();t.push({type:"Literal",value:")"}),r--,s=o.end}else break;else if(e.check(h.PIPE)){let o=e.advance();t.push({type:"Literal",value:"|"}),s=o.end}else if(e.check(h.SEMICOLON))if(r>0){let o=e.advance();t.push({type:"Literal",value:";"}),s=o.end}else break;else if(r>0&&e.check(h.LESS)){let o=e.advance();t.push({type:"Literal",value:"<"}),s=o.end}else if(r>0&&e.check(h.GREAT)){let o=e.advance();t.push({type:"Literal",value:">"}),s=o.end}else if(r>0&&e.check(h.DGREAT)){let o=e.advance();t.push({type:"Literal",value:">>"}),s=o.end}else if(r>0&&e.check(h.DLESS)){let o=e.advance();t.push({type:"Literal",value:"<<"}),s=o.end}else if(r>0&&e.check(h.LESSAND)){let o=e.advance();t.push({type:"Literal",value:"<&"}),s=o.end}else if(r>0&&e.check(h.GREATAND)){let o=e.advance();t.push({type:"Literal",value:">&"}),s=o.end}else if(r>0&&e.check(h.LESSGREAT)){let o=e.advance();t.push({type:"Literal",value:"<>"}),s=o.end}else if(r>0&&e.check(h.CLOBBER)){let o=e.advance();t.push({type:"Literal",value:">|"}),s=o.end}else if(r>0&&e.check(h.TLESS)){let o=e.advance();t.push({type:"Literal",value:"<<<"}),s=o.end}else if(r>0&&e.check(h.AMP)){let o=e.advance();t.push({type:"Literal",value:"&"}),s=o.end}else if(r>0&&e.check(h.LBRACE)){let o=e.advance();t.push({type:"Literal",value:"{"}),s=o.end}else if(r>0&&e.check(h.RBRACE)){let o=e.advance();t.push({type:"Literal",value:"}"}),s=o.end}else break}return t.length===0&&e.error("Expected regex pattern after =~"),{type:"Word",parts:t}}function Gr(e,t){let r=1,s=t+1;for(;s<e.length&&r>0;){let n=e[s];if(n==="\\"){s+=2;continue}if("@*+?!".includes(n)&&s+1<e.length&&e[s+1]==="("){s++,r++,s++;continue}if(n==="(")r++;else if(n===")"&&(r--,r===0))return s;s++}return-1}function Ur(e,t,r){let s=r+1,n=t[s];if("@*#?$!-0123456789".includes(n))return{part:w.parameterExpansion(n),endIndex:s+1};let a="";for(;s<t.length&&/[a-zA-Z0-9_]/.test(t[s]);)a+=t[s],s++;return{part:w.parameterExpansion(a),endIndex:s}}function Hr(e,t,r,s=!1){let n=r+2,a=!1;t[n]==="!"&&(a=!0,n++);let i=!1;t[n]==="#"&&!/[}:#%/^,]/.test(t[n+1]||"}")&&(i=!0,n++);let l="",o=t[n];if(/[@*#?$!-]/.test(o)&&!/[a-zA-Z0-9_]/.test(t[n+1]||""))l=o,n++;else for(;n<t.length&&/[a-zA-Z0-9_]/.test(t[n]);)l+=t[n],n++;if(t[n]==="["){let c=Ue(e,t,n,"[","]");if(l+=t.slice(n,c+1),n=c+1,t[n]==="["){let f=1,p=n;for(;p<t.length&&f>0;)t[p]==="{"?f++:t[p]==="}"&&f--,f>0&&p++;let d=t.slice(r+2,p);return{part:w.parameterExpansion("",{type:"BadSubstitution",text:d}),endIndex:p+1}}}if(l===""&&!a&&!i&&t[n]!=="}"){let c=1,f=n;for(;f<t.length&&c>0;)t[f]==="{"?c++:t[f]==="}"&&c--,c>0&&f++;if(c>0)throw new G("unexpected EOF while looking for matching '}'",0,0);let p=t.slice(r+2,f);return{part:w.parameterExpansion("",{type:"BadSubstitution",text:p}),endIndex:f+1}}let u=null;if(a){let c=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(c)if(n<t.length&&t[n]!=="}"&&/[:=\-+?#%/^,@]/.test(t[n])){let f=at(e,t,n,l,s);f.operation?(u={type:"Indirection",innerOp:f.operation},n=f.endIndex):(u={type:"ArrayKeys",array:c[1],star:c[2]==="*"},l="")}else u={type:"ArrayKeys",array:c[1],star:c[2]==="*"},l="";else if(t[n]==="*"||t[n]==="@"&&!/[QPaAEKkuUL]/.test(t[n+1]||"")){let f=t[n];n++,u={type:"VarNamePrefix",prefix:l,star:f==="*"},l=""}else if(n<t.length&&t[n]!=="}"&&/[:=\-+?#%/^,@]/.test(t[n])){let f=at(e,t,n,l,s);f.operation?(u={type:"Indirection",innerOp:f.operation},n=f.endIndex):u={type:"Indirection"}}else u={type:"Indirection"}}else if(i)if(t[n]===":")for(u={type:"LengthSliceError"};n<t.length&&t[n]!=="}";)n++;else t[n]!=="}"&&/[-+=?]/.test(t[n])?e.error(`\${#${l}${t.slice(n,t.indexOf("}",n))}}: bad substitution`):t[n]==="/"?e.error(`\${#${l}${t.slice(n,t.indexOf("}",n))}}: bad substitution`):u={type:"Length"};if(!u&&n<t.length&&t[n]!=="}"){let c=at(e,t,n,l,s);u=c.operation,n=c.endIndex}if(n<t.length&&t[n]!=="}"){let c=t[n];if(!/[:\-+=?#%/^,@[]/.test(c)){let f=n;for(;f<t.length&&t[f]!=="}";)f++;let p=t.slice(r,f+1);e.error(`\${${p.slice(2,-1)}}: bad substitution`)}}for(;n<t.length&&t[n]!=="}";)n++;if(n>=t.length)throw new G("unexpected EOF while looking for matching '}'",0,0);return{part:w.parameterExpansion(l,u),endIndex:n+1}}function at(e,t,r,s,n=!1){let a=r,i=t[a],l=t[a+1]||"";if(i===":"){let o=l;if("-=?+".includes(o)){a+=2;let A=ue(e,t,a),S=t.slice(a,A),y=ae(e,S,!1,!1,!0,!1,n,!1,!1,!0),b=w.word(y.length>0?y:[w.literal("")]);if(o==="-")return{operation:{type:"DefaultValue",word:b,checkEmpty:!0},endIndex:A};if(o==="=")return{operation:{type:"AssignDefault",word:b,checkEmpty:!0},endIndex:A};if(o==="?")return{operation:{type:"ErrorIfUnset",word:b,checkEmpty:!0},endIndex:A};if(o==="+")return{operation:{type:"UseAlternative",word:b,checkEmpty:!0},endIndex:A}}a++;let u=ue(e,t,a),c=t.slice(a,u),f=-1,p=0,d=0;for(let E=0;E<c.length;E++){let A=c[E];if(A==="("||A==="[")p++;else if(A===")"||A==="]")p--;else if(A==="?"&&p===0)d++;else if(A===":"&&p===0)if(d>0)d--;else{f=E;break}}let g=f>=0?c.slice(0,f):c,m=f>=0?c.slice(f+1):null;return{operation:{type:"Substring",offset:He(e,g),length:m!==null?He(e,m):null},endIndex:u}}if("-=?+".includes(i)){a++;let o=ue(e,t,a),u=t.slice(a,o),c=ae(e,u,!1,!1,!0,!1,n,!1,!1,!0),f=w.word(c.length>0?c:[w.literal("")]);if(i==="-")return{operation:{type:"DefaultValue",word:f,checkEmpty:!1},endIndex:o};if(i==="=")return{operation:{type:"AssignDefault",word:f,checkEmpty:!1},endIndex:o};if(i==="?")return{operation:{type:"ErrorIfUnset",word:u?f:null,checkEmpty:!1},endIndex:o};if(i==="+")return{operation:{type:"UseAlternative",word:f,checkEmpty:!1},endIndex:o}}if(i==="#"||i==="%"){let o=l===i,u=i==="#"?"prefix":"suffix";a+=o?2:1;let c=ue(e,t,a),f=t.slice(a,c),p=ae(e,f,!1,!1,!1);return{operation:{type:"PatternRemoval",pattern:w.word(p.length>0?p:[w.literal("")]),side:u,greedy:o},endIndex:c}}if(i==="/"){let o=l==="/";a+=o?2:1;let u=null;t[a]==="#"?(u="start",a++):t[a]==="%"&&(u="end",a++);let c;u!==null&&(t[a]==="/"||t[a]==="}")?c=a:c=Kt(e,t,a);let f=t.slice(a,c),p=ae(e,f,!1,!1,!1),d=w.word(p.length>0?p:[w.literal("")]),g=null,m=c;if(t[c]==="/"){let E=c+1,A=ue(e,t,E),S=t.slice(E,A),y=ae(e,S,!1,!1,!1);g=w.word(y.length>0?y:[w.literal("")]),m=A}return{operation:{type:"PatternReplacement",pattern:d,replacement:g,all:o,anchor:u},endIndex:m}}if(i==="^"||i===","){let o=l===i,u=i==="^"?"upper":"lower";a+=o?2:1;let c=ue(e,t,a),f=t.slice(a,c),p=f?w.word([w.literal(f)]):null;return{operation:{type:"CaseModification",direction:u,all:o,pattern:p},endIndex:c}}return i==="@"&&/[QPaAEKkuUL]/.test(l)?{operation:{type:"Transform",operator:l},endIndex:a+2}:{operation:null,endIndex:a}}function ot(e,t,r,s=!1){let n=r+1;if(n>=t.length)return{part:w.literal("$"),endIndex:n};let a=t[n];if(a==="("&&t[n+1]==="(")return e.isDollarDparenSubshell(t,r)?e.parseCommandSubstitution(t,r):e.parseArithmeticExpansion(t,r);if(a==="["){let i=1,l=n+1;for(;l<t.length&&i>0;)t[l]==="["?i++:t[l]==="]"&&i--,i>0&&l++;if(i===0){let o=t.slice(n+1,l),u=T(e,o);return{part:w.arithmeticExpansion(u),endIndex:l+1}}}return a==="("?e.parseCommandSubstitution(t,r):a==="{"?Hr(e,t,r,s):/[a-zA-Z_0-9@*#?$!-]/.test(a)?Ur(e,t,r):{part:w.literal("$"),endIndex:n}}function on(e,t){let r=[],s=0,n="",a=()=>{n&&(r.push(w.literal(n)),n="")};for(;s<t.length;){let i=t[s];if(i==="\\"&&s+1<t.length){let l=t[s+1];if(l==="$"||l==="`"||l==='"'||l==="\\"){n+=l,s+=2;continue}n+=i,s++;continue}if(i==="$"){a();let{part:l,endIndex:o}=ot(e,t,s,!0);l&&r.push(l),s=o;continue}if(i==="`"){a();let{part:l,endIndex:o}=e.parseBacktickSubstitution(t,s,!0);r.push(l),s=o;continue}n+=i,s++}return a(),r}function jr(e,t,r){let s=[],n=r,a="",i=()=>{a&&(s.push(w.literal(a)),a="")};for(;n<t.length&&t[n]!=='"';){let l=t[n];if(l==="\\"&&n+1<t.length){let o=t[n+1];if('"\\$`\n'.includes(o)){a+=o,n+=2;continue}a+=l,n++;continue}if(l==="$"){i();let{part:o,endIndex:u}=ot(e,t,n,!0);o&&s.push(o),n=u;continue}if(l==="`"){i();let{part:o,endIndex:u}=e.parseBacktickSubstitution(t,n,!0);s.push(o),n=u;continue}a+=l,n++}return i(),{part:w.doubleQuoted(s),endIndex:n}}function ae(e,t,r=!1,s=!1,n=!1,a=!1,i=!1,l=!1,o=!1,u=!1){if(s)return[w.singleQuoted(t)];if(r){let g=on(e,t);return[w.doubleQuoted(g)]}if(t.length>=2&&t[0]==='"'&&t[t.length-1]==='"'){let g=t.slice(1,-1),m=!1;for(let E=0;E<g.length;E++){if(g[E]==='"'){m=!0;break}g[E]==="\\"&&E+1<g.length&&E++}if(!m){let E=on(e,g);return[w.doubleQuoted(E)]}}let c=[],f=0,p="",d=()=>{p&&(c.push(w.literal(p)),p="")};for(;f<t.length;){let g=t[f];if(g==="\\"&&f+1<t.length){let m=t[f+1];if(o){d(),c.push(w.escaped(m)),f+=2;continue}let E=a?m==="$"||m==="`"||m===`
|
|
43
|
+
`);)f=!0,c++;if(f&&c<s&&r[c]===")")return!0}if(a===0)return!1;n++;continue}if(a===1&&(o==="|"&&n+1<s&&r[n+1]==="|"||o==="&"&&n+1<s&&r[n+1]==="&"||o==="|"&&n+1<s&&r[n+1]!=="|"))return!0;n++}return!1}};var Ze=1e6,Ge=1e5,Zt=1e6,Ue=200,Gt=new Set([h.LESS,h.GREAT,h.DLESS,h.DGREAT,h.LESSAND,h.GREATAND,h.LESSGREAT,h.DLESSDASH,h.CLOBBER,h.TLESS,h.AND_GREAT,h.AND_DGREAT]),Ut=new Set([h.LESS,h.GREAT,h.DLESS,h.DGREAT,h.LESSAND,h.GREATAND,h.LESSGREAT,h.DLESSDASH,h.CLOBBER,h.TLESS]),Ht=new Set([h.LESS,h.GREAT,h.DLESS,h.DGREAT,h.LESSAND,h.GREATAND,h.LESSGREAT,h.DLESSDASH,h.CLOBBER,h.TLESS,h.AND_GREAT,h.AND_DGREAT]),z=class extends Error{line;column;token;constructor(t,r,s,n=void 0){super(`Parse error at ${r}:${s}: ${t}`),this.line=r,this.column=s,this.token=n,this.name="ParseException"}};function _r(e){let t="",r=0;for(;r<e.length;){let s=e[r];if(s<128){t+=String.fromCharCode(s),r++;continue}if((s&224)===192){if(r+1<e.length&&(e[r+1]&192)===128&&s>=194){let n=(s&31)<<6|e[r+1]&63;t+=String.fromCharCode(n),r+=2;continue}t+=String.fromCharCode(s),r++;continue}if((s&240)===224){if(r+2<e.length&&(e[r+1]&192)===128&&(e[r+2]&192)===128){if(s===224&&e[r+1]<160){t+=String.fromCharCode(s),r++;continue}let n=(s&15)<<12|(e[r+1]&63)<<6|e[r+2]&63;if(n>=55296&&n<=57343){t+=String.fromCharCode(s),r++;continue}t+=String.fromCharCode(n),r+=3;continue}t+=String.fromCharCode(s),r++;continue}if((s&248)===240&&s<=244){if(r+3<e.length&&(e[r+1]&192)===128&&(e[r+2]&192)===128&&(e[r+3]&192)===128){if(s===240&&e[r+1]<144){t+=String.fromCharCode(s),r++;continue}let n=(s&7)<<18|(e[r+1]&63)<<12|(e[r+2]&63)<<6|e[r+3]&63;if(n>1114111){t+=String.fromCharCode(s),r++;continue}t+=String.fromCodePoint(n),r+=4;continue}t+=String.fromCharCode(s),r++;continue}t+=String.fromCharCode(s),r++}return t}function Kt(e,t,r){let s=r+1;for(;s<t.length&&/[a-zA-Z0-9_-]/.test(t[s]);)s++;return s}function He(e,t,r,s,n){let a=1,i=r+1;for(;i<t.length&&a>0;)t[i]===s?a++:t[i]===n&&a--,a>0&&i++;return a===0?i:-1}function ue(e,t,r){let s=r,n=1;for(;s<t.length&&n>0;){let a=t[s];if(a==="\\"&&s+1<t.length){s+=2;continue}if(a==="'"){let i=t.indexOf("'",s+1);if(i!==-1){s=i+1;continue}}if(a==='"'){for(s++;s<t.length&&t[s]!=='"';)t[s]==="\\"&&s+1<t.length?s+=2:s++;s<t.length&&s++;continue}a==="{"?n++:a==="}"&&n--,n>0&&s++}return s}function Xt(e,t,r){let s=r,n=!1;for(;s<t.length;){let a=t[s];if(a==="/"&&n||a==="}")break;if(a==="'"){let i=t.indexOf("'",s+1);if(i!==-1){s=i+1,n=!0;continue}}if(a==='"'){for(s++;s<t.length&&t[s]!=='"';)t[s]==="\\"&&s+1<t.length?s+=2:s++;s<t.length&&s++,n=!0;continue}a==="\\"?(s+=2,n=!0):(s++,n=!0)}return s}function Jt(e,t,r){let s=r,n="";for(;s<t.length;){let a=t[s];if(a==="*"||a==="?")n+=a,s++;else if(a==="["){let i=Cr(t,s);i===-1?(n+=a,s++):(n+=t.slice(s,i+1),s=i+1)}else break}return{pattern:n,endIndex:s}}function Cr(e,t){let r=t+1;for(r<e.length&&e[r]==="^"&&r++,r<e.length&&e[r]==="]"&&r++;r<e.length;){let s=e[r];if(s==="\\"&&r+1<e.length){let n=e[r+1];if(n==='"'||n==="'")return-1;r+=2;continue}if(s==="]")return r;if(s==='"'||s==="$"||s==="`")return-1;if(s==="'"){let n=e.indexOf("'",r+1);if(n!==-1){r=n+1;continue}}if(s==="["&&r+1<e.length&&e[r+1]===":"){let n=e.indexOf(":]",r+2);if(n!==-1){r=n+2;continue}}if(s==="["&&r+1<e.length&&(e[r+1]==="."||e[r+1]==="=")){let a=`${e[r+1]}]`,i=e.indexOf(a,r+2);if(i!==-1){r=i+2;continue}}r++}return-1}function Yt(e,t,r){let s="",n=r;for(;n<t.length&&t[n]!=="'";){let a=t[n];if(a==="\\"&&n+1<t.length)switch(t[n+1]){case"n":s+=`
|
|
44
|
+
`,n+=2;break;case"t":s+=" ",n+=2;break;case"r":s+="\r",n+=2;break;case"\\":s+="\\",n+=2;break;case"'":s+="'",n+=2;break;case'"':s+='"',n+=2;break;case"a":s+="\x07",n+=2;break;case"b":s+="\b",n+=2;break;case"e":case"E":s+="\x1B",n+=2;break;case"f":s+="\f",n+=2;break;case"v":s+="\v",n+=2;break;case"x":{let l=[],o=n;for(;o+1<t.length&&t[o]==="\\"&&t[o+1]==="x";){let u=t.slice(o+2,o+4),c=parseInt(u,16);if(!Number.isNaN(c)&&u.length>0)l.push(c),o+=2+u.length;else break}l.length>0?(s+=_r(l),n=o):(s+="\\x",n+=2);break}case"u":{let l=t.slice(n+2,n+6),o=parseInt(l,16);Number.isNaN(o)?(s+="\\u",n+=2):(s+=String.fromCharCode(o),n+=6);break}case"c":{if(n+2<t.length){let o=t[n+2].charCodeAt(0)&31;s+=String.fromCharCode(o),n+=3}else s+="\\c",n+=2;break}case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":{let l="",o=n+1;for(;o<t.length&&o<n+4&&/[0-7]/.test(t[o]);)l+=t[o],o++;let u=parseInt(l,8);s+=String.fromCharCode(u),n=o;break}default:s+=a,n++}else s+=a,n++}return n<t.length&&t[n]==="'"&&n++,{part:w.literal(s),endIndex:n}}function je(e,t){let r=t.trim();return r===""?{type:"ArithmeticExpression",expression:{type:"ArithNumber",value:0}}:T(e,r)}function jt(e){let t=[],r="",s=0;for(let n=0;n<e.length;n++){let a=e[n];a==="{"?(s++,r+=a):a==="}"?(s--,r+=a):a===","&&s===0?(t.push(r),r=""):r+=a}return t.push(r),t}function en(e,t,r,s){let n=He(e,t,r,"{","}");if(n===-1)return null;let a=t.slice(r+1,n),i=a.match(/^(-?\d+)\.\.(-?\d+)(?:\.\.(-?\d+))?$/);if(i)return{part:{type:"BraceExpansion",items:[{type:"Range",start:Number.parseInt(i[1],10),end:Number.parseInt(i[2],10),step:i[3]?Number.parseInt(i[3],10):void 0,startStr:i[1],endStr:i[2]}]},endIndex:n+1};let l=a.match(/^([a-zA-Z])\.\.([a-zA-Z])(?:\.\.(-?\d+))?$/);return l?{part:{type:"BraceExpansion",items:[{type:"Range",start:l[1],end:l[2],step:l[3]?Number.parseInt(l[3],10):void 0}]},endIndex:n+1}:a.includes(",")&&s?{part:{type:"BraceExpansion",items:jt(a).map(c=>({type:"Word",word:w.word(s(e,c,!1,!1,!1))}))},endIndex:n+1}:a.includes(",")?{part:{type:"BraceExpansion",items:jt(a).map(c=>({type:"Word",word:w.word([w.literal(c)])}))},endIndex:n+1}:null}function Ke(e,t){let r="";for(let s of t.parts)switch(s.type){case"Literal":r+=s.value;break;case"SingleQuoted":r+=`'${s.value}'`;break;case"Escaped":r+=s.value;break;case"DoubleQuoted":r+='"';for(let n of s.parts)n.type==="Literal"||n.type==="Escaped"?r+=n.value:n.type==="ParameterExpansion"&&(r+=`\${${n.parameter}}`);r+='"';break;case"ParameterExpansion":r+=`\${${s.parameter}}`;break;case"Glob":r+=s.pattern;break;case"TildeExpansion":r+="~",s.user&&(r+=s.user);break;case"BraceExpansion":{r+="{";let n=[];for(let a of s.items)if(a.type==="Range"){let i=a.startStr??String(a.start),l=a.endStr??String(a.end);a.step!==void 0?n.push(`${i}..${l}..${a.step}`):n.push(`${i}..${l}`)}else n.push(Ke(e,a.word));n.length===1&&s.items[0].type==="Range"?r+=n[0]:r+=n.join(","),r+="}";break}default:r+=s.type}return r}function tn(e,t){return{[h.LESS]:"<",[h.GREAT]:">",[h.DGREAT]:">>",[h.LESSAND]:"<&",[h.GREATAND]:">&",[h.LESSGREAT]:"<>",[h.CLOBBER]:">|",[h.TLESS]:"<<<",[h.AND_GREAT]:"&>",[h.AND_DGREAT]:"&>>",[h.DLESS]:"<",[h.DLESSDASH]:"<"}[t]||">"}function ve(e){let t=e.current(),r=t.type;if(r===h.NUMBER){let s=e.peek(1);return t.end!==s.start?!1:Ut.has(s.type)}if(r===h.FD_VARIABLE){let s=e.peek(1);return Ht.has(s.type)}return Gt.has(r)}function xe(e){let t=null,r;e.check(h.NUMBER)?t=Number.parseInt(e.advance().value,10):e.check(h.FD_VARIABLE)&&(r=e.advance().value);let s=e.advance(),n=tn(e,s.type);if(s.type===h.DLESS||s.type===h.DLESSDASH)return Or(e,n,t,s.type===h.DLESSDASH);e.isWord()||e.error("Expected redirection target");let a=e.parseWord();return w.redirection(n,a,t,r)}function Or(e,t,r,s){e.isWord()||e.error("Expected here-document delimiter");let n=e.advance(),a=n.value,i=n.quoted||!1;(a.startsWith("'")&&a.endsWith("'")||a.startsWith('"')&&a.endsWith('"'))&&(a=a.slice(1,-1));let l=w.redirection(s?"<<-":"<<",w.hereDoc(a,w.word([]),s,i),r);return e.addPendingHeredoc(l,a,s,i),l}function rn(e){let t=e.current().line,r=[],s=null,n=[],a=[];for(;e.check(h.ASSIGNMENT_WORD)||ve(e);)e.checkIterationLimit(),e.check(h.ASSIGNMENT_WORD)?r.push(Lr(e)):a.push(xe(e));if(e.isWord())s=e.parseWord();else if(r.length>0&&(e.check(h.DBRACK_START)||e.check(h.DPAREN_START))){let l=e.advance();s=w.word([w.literal(l.value)])}for(;(!e.isStatementEnd()||e.check(h.RBRACE))&&!e.check(h.PIPE,h.PIPE_AMP);)if(e.checkIterationLimit(),ve(e))a.push(xe(e));else if(e.check(h.RBRACE)){let l=e.advance();n.push(e.parseWordFromString(l.value,!1,!1))}else if(e.check(h.LBRACE)){let l=e.advance();n.push(e.parseWordFromString(l.value,!1,!1))}else if(e.check(h.DBRACK_END)){let l=e.advance();n.push(e.parseWordFromString(l.value,!1,!1))}else if(e.isWord())n.push(e.parseWord());else if(e.check(h.ASSIGNMENT_WORD)){let l=e.advance(),o=l.value,u=o.endsWith("="),c=o.endsWith("=(");if((u||c)&&(c||e.check(h.LPAREN))){let f=c?o.slice(0,-2):o.slice(0,-1);c||e.expect(h.LPAREN);let p=Xe(e);e.expect(h.RPAREN);let d=p.map(m=>Ke(e,m)),g=`${f}=(${d.join(" ")})`;n.push(e.parseWordFromString(g,!1,!1))}else n.push(e.parseWordFromString(o,l.quoted,l.singleQuoted))}else if(e.check(h.LPAREN))e.error("syntax error near unexpected token `('");else break;let i=w.simpleCommand(s,n,r,a);return i.line=t,i}function Lr(e){let t=e.expect(h.ASSIGNMENT_WORD),r=t.value,s=r.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);s||e.error(`Invalid assignment: ${r}`);let n=s[0],a,i=n.length;if(r[i]==="["){let f=0,p=i+1;for(;i<r.length;i++)if(r[i]==="[")f++;else if(r[i]==="]"&&(f--,f===0))break;f!==0&&e.error(`Invalid assignment: ${r}`),a=r.slice(p,i),i++}let l=r[i]==="+";l&&i++,r[i]!=="="&&e.error(`Invalid assignment: ${r}`),i++;let o=r.slice(i);if(o==="("){let f=Xe(e);e.expect(h.RPAREN);let p=a!==void 0?`${n}[${a}]`:n;return w.assignment(p,null,l,f)}if(o===""&&e.check(h.LPAREN)){let f=e.current();if(t.end===f.start){e.advance();let p=Xe(e);e.expect(h.RPAREN);let d=a!==void 0?`${n}[${a}]`:n;return w.assignment(d,null,l,p)}}let u=o?e.parseWordFromString(o,t.quoted,t.singleQuoted,!0):null,c=a!==void 0?`${n}[${a}]`:n;return w.assignment(c,u,l,null)}var Wr=new Set([h.AMP,h.PIPE,h.PIPE_AMP,h.SEMICOLON,h.AND_AND,h.OR_OR,h.DSEMI,h.SEMI_AND,h.SEMI_SEMI_AND]);function Xe(e){let t=[];for(e.skipNewlines();!e.check(h.RPAREN,h.EOF);)e.checkIterationLimit(),e.isWord()?t.push(e.parseWord()):Wr.has(e.current().type)?e.error(`syntax error near unexpected token \`${e.current().value}'`):e.advance(),e.skipNewlines();return t}function Je(e,t){e.expect(h.IF);let r=[],s=e.parseCompoundList();e.expect(h.THEN);let n=e.parseCompoundList();if(n.length===0){let l=e.check(h.FI)?"fi":e.check(h.ELSE)?"else":e.check(h.ELIF)?"elif":"fi";e.error(`syntax error near unexpected token \`${l}'`)}for(r.push({condition:s,body:n});e.check(h.ELIF);){e.advance();let l=e.parseCompoundList();e.expect(h.THEN);let o=e.parseCompoundList();if(o.length===0){let u=e.check(h.FI)?"fi":e.check(h.ELSE)?"else":e.check(h.ELIF)?"elif":"fi";e.error(`syntax error near unexpected token \`${u}'`)}r.push({condition:l,body:o})}let a=null;e.check(h.ELSE)&&(e.advance(),a=e.parseCompoundList(),a.length===0&&e.error("syntax error near unexpected token `fi'")),e.expect(h.FI);let i=t?.skipRedirections?[]:e.parseOptionalRedirections();return w.ifNode(r,a,i)}function Ye(e,t){let r=e.expect(h.FOR);if(e.check(h.DPAREN_START))return Mr(e,t,r.line);e.isWord()||e.error("Expected variable name in for loop");let n=e.advance().value,a=null;if(e.skipNewlines(),e.check(h.IN))for(e.advance(),a=[];!e.check(h.SEMICOLON,h.NEWLINE,h.DO,h.EOF)&&e.isWord();)a.push(e.parseWord());e.check(h.SEMICOLON)&&e.advance(),e.skipNewlines(),e.expect(h.DO);let i=e.parseCompoundList();e.expect(h.DONE);let l=t?.skipRedirections?[]:e.parseOptionalRedirections();return w.forNode(n,a,i,l)}function Mr(e,t,r){e.expect(h.DPAREN_START);let s=null,n=null,a=null,i=["","",""],l=0,o=0;for(;!e.check(h.DPAREN_END,h.EOF);){let f=e.advance();if(f.type===h.SEMICOLON&&o===0){if(l++,l>2)break}else f.value==="("&&o++,f.value===")"&&o--,i[l]+=f.value}e.expect(h.DPAREN_END),i[0].trim()&&(s=T(e,i[0].trim())),i[1].trim()&&(n=T(e,i[1].trim())),i[2].trim()&&(a=T(e,i[2].trim())),e.skipNewlines(),e.check(h.SEMICOLON)&&e.advance(),e.skipNewlines();let u;e.check(h.LBRACE)?(e.advance(),u=e.parseCompoundList(),e.expect(h.RBRACE)):(e.expect(h.DO),u=e.parseCompoundList(),e.expect(h.DONE));let c=t?.skipRedirections?[]:e.parseOptionalRedirections();return{type:"CStyleFor",init:s,condition:n,update:a,body:u,redirections:c,line:r}}function et(e,t){e.expect(h.WHILE);let r=e.parseCompoundList();e.expect(h.DO);let s=e.parseCompoundList();s.length===0&&e.error("syntax error near unexpected token `done'"),e.expect(h.DONE);let n=t?.skipRedirections?[]:e.parseOptionalRedirections();return w.whileNode(r,s,n)}function tt(e,t){e.expect(h.UNTIL);let r=e.parseCompoundList();e.expect(h.DO);let s=e.parseCompoundList();s.length===0&&e.error("syntax error near unexpected token `done'"),e.expect(h.DONE);let n=t?.skipRedirections?[]:e.parseOptionalRedirections();return w.untilNode(r,s,n)}function nt(e,t){e.expect(h.CASE),e.isWord()||e.error("Expected word after 'case'");let r=e.parseWord();e.skipNewlines(),e.expect(h.IN),e.skipNewlines();let s=[];for(;!e.check(h.ESAC,h.EOF);){e.checkIterationLimit();let a=e.getPos(),i=Vr(e);if(i&&s.push(i),e.skipNewlines(),e.getPos()===a&&!i)break}e.expect(h.ESAC);let n=t?.skipRedirections?[]:e.parseOptionalRedirections();return w.caseNode(r,s,n)}function Vr(e){e.check(h.LPAREN)&&e.advance();let t=[];for(;e.isWord()&&(t.push(e.parseWord()),e.check(h.PIPE));)e.advance();if(t.length===0)return null;e.expect(h.RPAREN),e.skipNewlines();let r=[];for(;!e.check(h.DSEMI,h.SEMI_AND,h.SEMI_SEMI_AND,h.ESAC,h.EOF);){e.checkIterationLimit(),e.isWord()&&e.peek(1).type===h.RPAREN&&e.error("syntax error near unexpected token `)'"),e.check(h.LPAREN)&&e.peek(1).type===h.WORD&&e.error(`syntax error near unexpected token \`${e.peek(1).value}'`);let n=e.getPos(),a=e.parseStatement();if(a&&r.push(a),e.skipSeparators(!1),e.getPos()===n&&!a)break}let s=";;";return e.check(h.DSEMI)?(e.advance(),s=";;"):e.check(h.SEMI_AND)?(e.advance(),s=";&"):e.check(h.SEMI_SEMI_AND)&&(e.advance(),s=";;&"),w.caseItem(t,r,s)}function rt(e,t){e.expect(h.LPAREN);let r=e.parseCompoundList();e.expect(h.RPAREN);let s=t?.skipRedirections?[]:e.parseOptionalRedirections();return w.subshell(r,s)}function st(e,t){e.expect(h.LBRACE);let r=e.parseCompoundList();e.expect(h.RBRACE);let s=t?.skipRedirections?[]:e.parseOptionalRedirections();return w.group(r,s)}var Br=["-a","-b","-c","-d","-e","-f","-g","-h","-k","-p","-r","-s","-t","-u","-w","-x","-G","-L","-N","-O","-S","-z","-n","-o","-v","-R"],Fr=["==","!=","=~","<",">","-eq","-ne","-lt","-le","-gt","-ge","-nt","-ot","-ef"];function sn(e){return e.isWord()||e.check(h.LBRACE)||e.check(h.RBRACE)||e.check(h.ASSIGNMENT_WORD)}function an(e){if(e.check(h.BANG)&&e.peek(1).type===h.LPAREN){e.advance(),e.advance();let t=1,r="!(";for(;t>0&&!e.check(h.EOF);)if(e.check(h.LPAREN))t++,r+="(",e.advance();else if(e.check(h.RPAREN))t--,t>0&&(r+=")"),e.advance();else if(e.isWord())r+=e.advance().value;else if(e.check(h.PIPE))r+="|",e.advance();else break;return r+=")",e.parseWordFromString(r,!1,!1,!1,!1,!0)}return e.parseWordNoBraceExpansion()}function at(e){return e.skipNewlines(),Qr(e)}function Qr(e){let t=on(e);for(e.skipNewlines();e.check(h.OR_OR);){e.advance(),e.skipNewlines();let r=on(e);t={type:"CondOr",left:t,right:r},e.skipNewlines()}return t}function on(e){let t=it(e);for(e.skipNewlines();e.check(h.AND_AND);){e.advance(),e.skipNewlines();let r=it(e);t={type:"CondAnd",left:t,right:r},e.skipNewlines()}return t}function it(e){return e.skipNewlines(),e.check(h.BANG)?(e.advance(),e.skipNewlines(),{type:"CondNot",operand:it(e)}):zr(e)}function zr(e){if(e.check(h.LPAREN)){e.advance();let t=at(e);return e.expect(h.RPAREN),{type:"CondGroup",expression:t}}if(sn(e)){let t=e.current(),r=t.value;if(Br.includes(r)&&!t.quoted){if(e.advance(),e.check(h.DBRACK_END)&&e.error(`Expected operand after ${r}`),sn(e)){let a=e.parseWordNoBraceExpansion();return{type:"CondUnary",operator:r,operand:a}}let n=e.current();e.error(`unexpected argument \`${n.value}' to conditional unary operator`)}let s=e.parseWordNoBraceExpansion();if(e.isWord()&&Fr.includes(e.current().value)){let n=e.advance().value,a;return n==="=~"?a=Zr(e):n==="=="||n==="!="?a=an(e):a=e.parseWordNoBraceExpansion(),{type:"CondBinary",operator:n,left:s,right:a}}if(e.check(h.LESS)){e.advance();let n=e.parseWordNoBraceExpansion();return{type:"CondBinary",operator:"<",left:s,right:n}}if(e.check(h.GREAT)){e.advance();let n=e.parseWordNoBraceExpansion();return{type:"CondBinary",operator:">",left:s,right:n}}if(e.isWord()&&e.current().value==="="){e.advance();let n=an(e);return{type:"CondBinary",operator:"==",left:s,right:n}}return{type:"CondWord",word:s}}e.error("Expected conditional expression")}function Zr(e){let t=[],r=0,s=-1,n=e.getInput(),a=()=>e.check(h.DBRACK_END)||e.check(h.AND_AND)||e.check(h.OR_OR)||e.check(h.NEWLINE)||e.check(h.EOF);for(;!a();){let i=e.current(),l=s>=0&&i.start>s;if(r===0&&l)break;if(r>0&&l){let o=n.slice(s,i.start);t.push({type:"Literal",value:o})}if(e.isWord()||e.check(h.ASSIGNMENT_WORD)){let o=e.parseWordForRegex();t.push(...o.parts),s=e.peek(-1).end}else if(e.check(h.LPAREN)){let o=e.advance();t.push({type:"Literal",value:"("}),r++,s=o.end}else if(e.check(h.DPAREN_START)){let o=e.advance();t.push({type:"Literal",value:"(("}),r+=2,s=o.end}else if(e.check(h.DPAREN_END))if(r>=2){let o=e.advance();t.push({type:"Literal",value:"))"}),r-=2,s=o.end}else{if(r===1)break;break}else if(e.check(h.RPAREN))if(r>0){let o=e.advance();t.push({type:"Literal",value:")"}),r--,s=o.end}else break;else if(e.check(h.PIPE)){let o=e.advance();t.push({type:"Literal",value:"|"}),s=o.end}else if(e.check(h.SEMICOLON))if(r>0){let o=e.advance();t.push({type:"Literal",value:";"}),s=o.end}else break;else if(r>0&&e.check(h.LESS)){let o=e.advance();t.push({type:"Literal",value:"<"}),s=o.end}else if(r>0&&e.check(h.GREAT)){let o=e.advance();t.push({type:"Literal",value:">"}),s=o.end}else if(r>0&&e.check(h.DGREAT)){let o=e.advance();t.push({type:"Literal",value:">>"}),s=o.end}else if(r>0&&e.check(h.DLESS)){let o=e.advance();t.push({type:"Literal",value:"<<"}),s=o.end}else if(r>0&&e.check(h.LESSAND)){let o=e.advance();t.push({type:"Literal",value:"<&"}),s=o.end}else if(r>0&&e.check(h.GREATAND)){let o=e.advance();t.push({type:"Literal",value:">&"}),s=o.end}else if(r>0&&e.check(h.LESSGREAT)){let o=e.advance();t.push({type:"Literal",value:"<>"}),s=o.end}else if(r>0&&e.check(h.CLOBBER)){let o=e.advance();t.push({type:"Literal",value:">|"}),s=o.end}else if(r>0&&e.check(h.TLESS)){let o=e.advance();t.push({type:"Literal",value:"<<<"}),s=o.end}else if(r>0&&e.check(h.AMP)){let o=e.advance();t.push({type:"Literal",value:"&"}),s=o.end}else if(r>0&&e.check(h.LBRACE)){let o=e.advance();t.push({type:"Literal",value:"{"}),s=o.end}else if(r>0&&e.check(h.RBRACE)){let o=e.advance();t.push({type:"Literal",value:"}"}),s=o.end}else break}return t.length===0&&e.error("Expected regex pattern after =~"),{type:"Word",parts:t}}function Ur(e,t){let r=1,s=t+1;for(;s<e.length&&r>0;){let n=e[s];if(n==="\\"){s+=2;continue}if("@*+?!".includes(n)&&s+1<e.length&&e[s+1]==="("){s++,r++,s++;continue}if(n==="(")r++;else if(n===")"&&(r--,r===0))return s;s++}return-1}function Hr(e,t,r){let s=r+1,n=t[s];if("@*#?$!-0123456789".includes(n))return{part:w.parameterExpansion(n),endIndex:s+1};let a="";for(;s<t.length&&/[a-zA-Z0-9_]/.test(t[s]);)a+=t[s],s++;return{part:w.parameterExpansion(a),endIndex:s}}function jr(e,t,r,s=!1){let n=r+2,a=!1;t[n]==="!"&&(a=!0,n++);let i=!1;t[n]==="#"&&!/[}:#%/^,]/.test(t[n+1]||"}")&&(i=!0,n++);let l="",o=t[n];if(/[@*#?$!-]/.test(o)&&!/[a-zA-Z0-9_]/.test(t[n+1]||""))l=o,n++;else for(;n<t.length&&/[a-zA-Z0-9_]/.test(t[n]);)l+=t[n],n++;if(t[n]==="["){let c=He(e,t,n,"[","]");if(l+=t.slice(n,c+1),n=c+1,t[n]==="["){let f=1,p=n;for(;p<t.length&&f>0;)t[p]==="{"?f++:t[p]==="}"&&f--,f>0&&p++;let d=t.slice(r+2,p);return{part:w.parameterExpansion("",{type:"BadSubstitution",text:d}),endIndex:p+1}}}if(l===""&&!a&&!i&&t[n]!=="}"){let c=1,f=n;for(;f<t.length&&c>0;)t[f]==="{"?c++:t[f]==="}"&&c--,c>0&&f++;if(c>0)throw new z("unexpected EOF while looking for matching '}'",0,0);let p=t.slice(r+2,f);return{part:w.parameterExpansion("",{type:"BadSubstitution",text:p}),endIndex:f+1}}let u=null;if(a){let c=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(c)if(n<t.length&&t[n]!=="}"&&/[:=\-+?#%/^,@]/.test(t[n])){let f=ot(e,t,n,l,s);f.operation?(u={type:"Indirection",innerOp:f.operation},n=f.endIndex):(u={type:"ArrayKeys",array:c[1],star:c[2]==="*"},l="")}else u={type:"ArrayKeys",array:c[1],star:c[2]==="*"},l="";else if(t[n]==="*"||t[n]==="@"&&!/[QPaAEKkuUL]/.test(t[n+1]||"")){let f=t[n];n++,u={type:"VarNamePrefix",prefix:l,star:f==="*"},l=""}else if(n<t.length&&t[n]!=="}"&&/[:=\-+?#%/^,@]/.test(t[n])){let f=ot(e,t,n,l,s);f.operation?(u={type:"Indirection",innerOp:f.operation},n=f.endIndex):u={type:"Indirection"}}else u={type:"Indirection"}}else if(i)if(t[n]===":")for(u={type:"LengthSliceError"};n<t.length&&t[n]!=="}";)n++;else t[n]!=="}"&&/[-+=?]/.test(t[n])?e.error(`\${#${l}${t.slice(n,t.indexOf("}",n))}}: bad substitution`):t[n]==="/"?e.error(`\${#${l}${t.slice(n,t.indexOf("}",n))}}: bad substitution`):u={type:"Length"};if(!u&&n<t.length&&t[n]!=="}"){let c=ot(e,t,n,l,s);u=c.operation,n=c.endIndex}if(n<t.length&&t[n]!=="}"){let c=t[n];if(!/[:\-+=?#%/^,@[]/.test(c)){let f=n;for(;f<t.length&&t[f]!=="}";)f++;let p=t.slice(r,f+1);e.error(`\${${p.slice(2,-1)}}: bad substitution`)}}for(;n<t.length&&t[n]!=="}";)n++;if(n>=t.length)throw new z("unexpected EOF while looking for matching '}'",0,0);return{part:w.parameterExpansion(l,u),endIndex:n+1}}function ot(e,t,r,s,n=!1){let a=r,i=t[a],l=t[a+1]||"";if(i===":"){let o=l;if("-=?+".includes(o)){a+=2;let A=ue(e,t,a),S=t.slice(a,A),y=ae(e,S,!1,!1,!0,!1,n,!1,!1,!0),b=w.word(y.length>0?y:[w.literal("")]);if(o==="-")return{operation:{type:"DefaultValue",word:b,checkEmpty:!0},endIndex:A};if(o==="=")return{operation:{type:"AssignDefault",word:b,checkEmpty:!0},endIndex:A};if(o==="?")return{operation:{type:"ErrorIfUnset",word:b,checkEmpty:!0},endIndex:A};if(o==="+")return{operation:{type:"UseAlternative",word:b,checkEmpty:!0},endIndex:A}}a++;let u=ue(e,t,a),c=t.slice(a,u),f=-1,p=0,d=0;for(let E=0;E<c.length;E++){let A=c[E];if(A==="("||A==="[")p++;else if(A===")"||A==="]")p--;else if(A==="?"&&p===0)d++;else if(A===":"&&p===0)if(d>0)d--;else{f=E;break}}let g=f>=0?c.slice(0,f):c,m=f>=0?c.slice(f+1):null;return{operation:{type:"Substring",offset:je(e,g),length:m!==null?je(e,m):null},endIndex:u}}if("-=?+".includes(i)){a++;let o=ue(e,t,a),u=t.slice(a,o),c=ae(e,u,!1,!1,!0,!1,n,!1,!1,!0),f=w.word(c.length>0?c:[w.literal("")]);if(i==="-")return{operation:{type:"DefaultValue",word:f,checkEmpty:!1},endIndex:o};if(i==="=")return{operation:{type:"AssignDefault",word:f,checkEmpty:!1},endIndex:o};if(i==="?")return{operation:{type:"ErrorIfUnset",word:u?f:null,checkEmpty:!1},endIndex:o};if(i==="+")return{operation:{type:"UseAlternative",word:f,checkEmpty:!1},endIndex:o}}if(i==="#"||i==="%"){let o=l===i,u=i==="#"?"prefix":"suffix";a+=o?2:1;let c=ue(e,t,a),f=t.slice(a,c),p=ae(e,f,!1,!1,!1);return{operation:{type:"PatternRemoval",pattern:w.word(p.length>0?p:[w.literal("")]),side:u,greedy:o},endIndex:c}}if(i==="/"){let o=l==="/";a+=o?2:1;let u=null;t[a]==="#"?(u="start",a++):t[a]==="%"&&(u="end",a++);let c;u!==null&&(t[a]==="/"||t[a]==="}")?c=a:c=Xt(e,t,a);let f=t.slice(a,c),p=ae(e,f,!1,!1,!1),d=w.word(p.length>0?p:[w.literal("")]),g=null,m=c;if(t[c]==="/"){let E=c+1,A=ue(e,t,E),S=t.slice(E,A),y=ae(e,S,!1,!1,!1);g=w.word(y.length>0?y:[w.literal("")]),m=A}return{operation:{type:"PatternReplacement",pattern:d,replacement:g,all:o,anchor:u},endIndex:m}}if(i==="^"||i===","){let o=l===i,u=i==="^"?"upper":"lower";a+=o?2:1;let c=ue(e,t,a),f=t.slice(a,c),p=f?w.word([w.literal(f)]):null;return{operation:{type:"CaseModification",direction:u,all:o,pattern:p},endIndex:c}}return i==="@"&&/[QPaAEKkuUL]/.test(l)?{operation:{type:"Transform",operator:l},endIndex:a+2}:{operation:null,endIndex:a}}function lt(e,t,r,s=!1){let n=r+1;if(n>=t.length)return{part:w.literal("$"),endIndex:n};let a=t[n];if(a==="("&&t[n+1]==="(")return e.isDollarDparenSubshell(t,r)?e.parseCommandSubstitution(t,r):e.parseArithmeticExpansion(t,r);if(a==="["){let i=1,l=n+1;for(;l<t.length&&i>0;)t[l]==="["?i++:t[l]==="]"&&i--,i>0&&l++;if(i===0){let o=t.slice(n+1,l),u=T(e,o);return{part:w.arithmeticExpansion(u),endIndex:l+1}}}return a==="("?e.parseCommandSubstitution(t,r):a==="{"?jr(e,t,r,s):/[a-zA-Z_0-9@*#?$!-]/.test(a)?Hr(e,t,r):{part:w.literal("$"),endIndex:n}}function ln(e,t){let r=[],s=0,n="",a=()=>{n&&(r.push(w.literal(n)),n="")};for(;s<t.length;){let i=t[s];if(i==="\\"&&s+1<t.length){let l=t[s+1];if(l==="$"||l==="`"||l==='"'||l==="\\"){n+=l,s+=2;continue}n+=i,s++;continue}if(i==="$"){a();let{part:l,endIndex:o}=lt(e,t,s,!0);l&&r.push(l),s=o;continue}if(i==="`"){a();let{part:l,endIndex:o}=e.parseBacktickSubstitution(t,s,!0);r.push(l),s=o;continue}n+=i,s++}return a(),r}function Kr(e,t,r){let s=[],n=r,a="",i=()=>{a&&(s.push(w.literal(a)),a="")};for(;n<t.length&&t[n]!=='"';){let l=t[n];if(l==="\\"&&n+1<t.length){let o=t[n+1];if('"\\$`\n'.includes(o)){a+=o,n+=2;continue}a+=l,n++;continue}if(l==="$"){i();let{part:o,endIndex:u}=lt(e,t,n,!0);o&&s.push(o),n=u;continue}if(l==="`"){i();let{part:o,endIndex:u}=e.parseBacktickSubstitution(t,n,!0);s.push(o),n=u;continue}a+=l,n++}return i(),{part:w.doubleQuoted(s),endIndex:n}}function ae(e,t,r=!1,s=!1,n=!1,a=!1,i=!1,l=!1,o=!1,u=!1){if(s)return[w.singleQuoted(t)];if(r){let g=ln(e,t);return[w.doubleQuoted(g)]}if(t.length>=2&&t[0]==='"'&&t[t.length-1]==='"'){let g=t.slice(1,-1),m=!1;for(let E=0;E<g.length;E++){if(g[E]==='"'){m=!0;break}g[E]==="\\"&&E+1<g.length&&E++}if(!m){let E=ln(e,g);return[w.doubleQuoted(E)]}}let c=[],f=0,p="",d=()=>{p&&(c.push(w.literal(p)),p="")};for(;f<t.length;){let g=t[f];if(g==="\\"&&f+1<t.length){let m=t[f+1];if(o){d(),c.push(w.escaped(m)),f+=2;continue}let E=a?m==="$"||m==="`"||m===`
|
|
45
45
|
`:m==="$"||m==="`"||m==='"'||m==="'"||m===`
|
|
46
|
-
`||u&&m==="}",A=i?"*?[]\\".includes(m):"*?[]\\(){}.^+".includes(m);E?p+=m:A?(d(),c.push(w.escaped(m))):p+=`\\${m}`,f+=2;continue}if(g==="'"&&!i&&!a){d();let m=t.indexOf("'",f+1);if(m===-1){p+=t.slice(f);break}c.push(w.singleQuoted(t.slice(f+1,m))),f=m+1;continue}if(g==='"'&&!a){d();let{part:m,endIndex:E}=
|
|
46
|
+
`||u&&m==="}",A=i?"*?[]\\".includes(m):"*?[]\\(){}.^+".includes(m);E?p+=m:A?(d(),c.push(w.escaped(m))):p+=`\\${m}`,f+=2;continue}if(g==="'"&&!i&&!a){d();let m=t.indexOf("'",f+1);if(m===-1){p+=t.slice(f);break}c.push(w.singleQuoted(t.slice(f+1,m))),f=m+1;continue}if(g==='"'&&!a){d();let{part:m,endIndex:E}=Kr(e,t,f+1);c.push(m),f=E+1;continue}if(g==="$"&&t[f+1]==="'"){d();let{part:m,endIndex:E}=Yt(e,t,f+2);c.push(m),f=E;continue}if(g==="$"){d();let{part:m,endIndex:E}=lt(e,t,f);m&&c.push(m),f=E;continue}if(g==="`"){d();let{part:m,endIndex:E}=e.parseBacktickSubstitution(t,f);c.push(m),f=E;continue}if(g==="~"){let m=f>0?t[f-1]:"";if(f===0||m==="="||n&&m===":"){let A=Kt(e,t,f),S=t[A];if(S===void 0||S==="/"||S===":"){d();let y=t.slice(f+1,A)||null;c.push({type:"TildeExpansion",user:y}),f=A;continue}}}if("@*+?!".includes(g)&&f+1<t.length&&t[f+1]==="("){let m=Ur(t,f+1);if(m!==-1){d();let E=t.slice(f,m+1);c.push({type:"Glob",pattern:E}),f=m+1;continue}}if(g==="*"||g==="?"||g==="["){d();let{pattern:m,endIndex:E}=Jt(e,t,f);c.push({type:"Glob",pattern:m}),f=E;continue}if(g==="{"&&!n&&!l){let m=en(e,t,f,ae);if(m){d(),c.push(m.part),f=m.endIndex;continue}}p+=g,f++}return d(),c}function cn(e,t){let r=e.length,s=t+3,n=2,a=!1,i=!1;for(;s<r&&n>0;){let l=e[s];if(a){l==="'"&&(a=!1),s++;continue}if(i){if(l==="\\"){s+=2;continue}l==='"'&&(i=!1),s++;continue}if(l==="'"){a=!0,s++;continue}if(l==='"'){i=!0,s++;continue}if(l==="\\"){s+=2;continue}if(l==="("){n++,s++;continue}if(l===")"){if(n--,n===1){let o=s+1;return!(o<r&&e[o]===")")}if(n===0)return!1;s++;continue}if(n===1&&(l==="|"&&s+1<r&&e[s+1]==="|"||l==="&"&&s+1<r&&e[s+1]==="&"||l==="|"&&s+1<r&&e[s+1]!=="|"))return!0;s++}return!1}function un(e,t,r,s){let n=t+2,a=1,i=n,l=!1,o=!1,u=0,c=!1,f="";for(;i<e.length&&a>0;){let m=e[i];l?m==="'"&&(l=!1):o?m==="\\"&&i+1<e.length?i++:m==='"'&&(o=!1):m==="'"?(l=!0,f=""):m==='"'?(o=!0,f=""):m==="\\"&&i+1<e.length?(i++,f=""):/[a-zA-Z_]/.test(m)?f+=m:(f==="case"?(u++,c=!1):f==="in"&&u>0?c=!0:f==="esac"&&u>0&&(u--,c=!1),f="",m==="("?i>0&&e[i-1]==="$"?a++:c||a++:m===")"?c?c=!1:a--:m===";"&&u>0&&i+1<e.length&&e[i+1]===";"&&(c=!0)),a>0&&i++}a>0&&s("unexpected EOF while looking for matching `)'");let p=e.slice(n,i),g=r().parse(p);return{part:w.commandSubstitution(g,!1),endIndex:i+1}}function fn(e,t,r,s,n){let i=t+1,l="";for(;i<e.length&&e[i]!=="`";)if(e[i]==="\\"){let c=e[i+1];c==="$"||c==="`"||c==="\\"||c===`
|
|
47
47
|
`||r&&c==='"'?(c!==`
|
|
48
|
-
`&&(l+=c),i+=2):(l+=e[i],i++)}else l+=e[i],i++;i>=e.length&&n("unexpected EOF while looking for matching ``'");let u=s().parse(l);return{part:w.commandSubstitution(u,!0),endIndex:i+1}}var M=class e{tokens=[];pos=0;pendingHeredocs=[];parseIterations=0;_input="";getInput(){return this._input}checkIterationLimit(){if(this.parseIterations++,this.parseIterations>zt)throw new G("Maximum parse iterations exceeded (possible infinite loop)",this.current().line,this.current().column)}parse(t){if(t.length>Ze)throw new G(`Input too large: ${t.length} bytes exceeds limit of ${Ze}`,1,1);this._input=t;let r=new ve(t);if(this.tokens=r.tokenize(),this.tokens.length>Ge)throw new G(`Too many tokens: ${this.tokens.length} exceeds limit of ${Ge}`,1,1);return this.pos=0,this.pendingHeredocs=[],this.parseIterations=0,this.parseScript()}parseTokens(t){return this.tokens=t,this.pos=0,this.pendingHeredocs=[],this.parseScript()}current(){return this.tokens[this.pos]||this.tokens[this.tokens.length-1]}peek(t=0){return this.tokens[this.pos+t]||this.tokens[this.tokens.length-1]}advance(){let t=this.current();return this.pos<this.tokens.length-1&&this.pos++,t}getPos(){return this.pos}check(t,r,s,n,...a){let i=this.tokens[this.pos]?.type;return i===t||r!==void 0&&i===r||s!==void 0&&i===s||n!==void 0&&i===n?!0:a.length>0?a.includes(i):!1}expect(t,r){if(this.check(t))return this.advance();let s=this.current();throw new G(r||`Expected ${t}, got ${s.type}`,s.line,s.column,s)}error(t){let r=this.current();throw new G(t,r.line,r.column,r)}skipNewlines(){for(;this.check(h.NEWLINE,h.COMMENT);)this.check(h.NEWLINE)?(this.advance(),this.processHeredocs()):this.advance()}skipSeparators(t=!0){for(;;){if(this.check(h.NEWLINE)){this.advance(),this.processHeredocs();continue}if(this.check(h.SEMICOLON,h.COMMENT)){this.advance();continue}if(t&&this.check(h.DSEMI,h.SEMI_AND,h.SEMI_SEMI_AND)){this.advance();continue}break}}addPendingHeredoc(t,r,s,n){this.pendingHeredocs.push({redirect:t,delimiter:r,stripTabs:s,quoted:n})}processHeredocs(){for(let t of this.pendingHeredocs)if(this.check(h.HEREDOC_CONTENT)){let r=this.advance(),s;t.quoted?s=w.word([w.literal(r.value)]):s=this.parseWordFromString(r.value,!1,!1,!1,!0),t.redirect.target=w.hereDoc(t.delimiter,s,t.stripTabs,t.quoted)}this.pendingHeredocs=[]}isStatementEnd(){return this.check(h.EOF,h.NEWLINE,h.SEMICOLON,h.AMP,h.AND_AND,h.OR_OR,h.RPAREN,h.RBRACE,h.DSEMI,h.SEMI_AND,h.SEMI_SEMI_AND)}isCommandStart(){let t=this.current().type;return t===h.WORD||t===h.NAME||t===h.NUMBER||t===h.ASSIGNMENT_WORD||t===h.IF||t===h.FOR||t===h.WHILE||t===h.UNTIL||t===h.CASE||t===h.LPAREN||t===h.LBRACE||t===h.DPAREN_START||t===h.DBRACK_START||t===h.FUNCTION||t===h.BANG||t===h.TIME||t===h.IN||t===h.LESS||t===h.GREAT||t===h.DLESS||t===h.DGREAT||t===h.LESSAND||t===h.GREATAND||t===h.LESSGREAT||t===h.DLESSDASH||t===h.CLOBBER||t===h.TLESS||t===h.AND_GREAT||t===h.AND_DGREAT}parseScript(){let t=[],s=0;for(this.skipNewlines();!this.check(h.EOF);){s++,s>1e4&&this.error("Parser stuck: too many iterations (>10000)");let n=this.checkUnexpectedToken();if(n){t.push(n),this.skipSeparators(!1);continue}let a=this.pos,i=this.parseStatement();i&&t.push(i),this.skipSeparators(!1),this.check(h.DSEMI,h.SEMI_AND,h.SEMI_SEMI_AND)&&this.error(`syntax error near unexpected token \`${this.current().value}'`),this.pos===a&&!this.check(h.EOF)&&this.advance()}return w.script(t)}checkUnexpectedToken(){let t=this.current().type,r=this.current().value;if((t===h.DO||t===h.DONE||t===h.THEN||t===h.ELSE||t===h.ELIF||t===h.FI||t===h.ESAC)&&this.error(`syntax error near unexpected token \`${r}'`),t===h.RBRACE||t===h.RPAREN){let s=`syntax error near unexpected token \`${r}'`;return this.advance(),w.statement([w.pipeline([w.simpleCommand(null,[],[],[])])],[],!1,{message:s,token:r})}return(t===h.DSEMI||t===h.SEMI_AND||t===h.SEMI_SEMI_AND)&&this.error(`syntax error near unexpected token \`${r}'`),t===h.SEMICOLON&&this.error(`syntax error near unexpected token \`${r}'`),(t===h.PIPE||t===h.PIPE_AMP)&&this.error(`syntax error near unexpected token \`${r}'`),null}parseStatement(){if(this.skipNewlines(),!this.isCommandStart())return null;let t=this.current().start,r=[],s=[],n=!1,a=this.parsePipeline();for(r.push(a);this.check(h.AND_AND,h.OR_OR);){let o=this.advance();s.push(o.type===h.AND_AND?"&&":"||"),this.skipNewlines();let u=this.parsePipeline();r.push(u)}this.check(h.AMP)&&(this.advance(),n=!0);let i=this.pos>0?this.tokens[this.pos-1].end:t,l=this._input.slice(t,i);return w.statement(r,s,n,void 0,l)}parsePipeline(){let t=!1,r=!1;this.check(h.TIME)&&(this.advance(),t=!0,this.check(h.WORD,h.NAME)&&this.current().value==="-p"&&(this.advance(),r=!0));let s=0;for(;this.check(h.BANG);)this.advance(),s++;let n=s%2===1,a=[],i=[],l=this.parseCommand();for(a.push(l);this.check(h.PIPE,h.PIPE_AMP);){let o=this.advance();this.skipNewlines(),i.push(o.type===h.PIPE_AMP);let u=this.parseCommand();a.push(u)}return w.pipeline(a,n,t,r,i.length>0?i:void 0)}parseCommand(){return this.check(h.IF)?Xe(this):this.check(h.FOR)?Je(this):this.check(h.WHILE)?Ye(this):this.check(h.UNTIL)?et(this):this.check(h.CASE)?tt(this):this.check(h.LPAREN)?nt(this):this.check(h.LBRACE)?rt(this):this.check(h.DPAREN_START)?this.dparenClosesWithSpacedParens()?this.parseNestedSubshellsFromDparen():this.parseArithmeticCommand():this.check(h.DBRACK_START)?this.parseConditionalCommand():this.check(h.FUNCTION)?this.parseFunctionDef():this.check(h.NAME,h.WORD)&&this.peek(1).type===h.LPAREN&&this.peek(2).type===h.RPAREN?this.parseFunctionDef():nn(this)}dparenClosesWithSpacedParens(){let t=1,r=1;for(;r<this.tokens.length-this.pos;){let s=this.peek(r);if(s.type===h.EOF)return!1;if(s.type===h.DPAREN_START||s.type===h.LPAREN)t++;else if(s.type===h.DPAREN_END){if(t-=2,t<=0)return!1}else if(s.type===h.RPAREN&&(t--,t===0&&this.peek(r+1).type===h.RPAREN))return!0;r++}return!1}parseNestedSubshellsFromDparen(){this.advance();let t=this.parseCompoundList();this.expect(h.RPAREN),this.expect(h.RPAREN);let r=this.parseOptionalRedirections(),s=w.subshell(t,[]);return w.subshell([w.statement([w.pipeline([s],!1,!1,!1)])],r)}isWord(){let t=this.current().type;return t===h.WORD||t===h.NAME||t===h.NUMBER||t===h.IF||t===h.FOR||t===h.WHILE||t===h.UNTIL||t===h.CASE||t===h.FUNCTION||t===h.ELSE||t===h.ELIF||t===h.FI||t===h.THEN||t===h.DO||t===h.DONE||t===h.ESAC||t===h.IN||t===h.SELECT||t===h.TIME||t===h.COPROC||t===h.BANG}parseWord(){let t=this.advance();return this.parseWordFromString(t.value,t.quoted,t.singleQuoted)}parseWordNoBraceExpansion(){let t=this.advance();return this.parseWordFromString(t.value,t.quoted,t.singleQuoted,!1,!1,!0)}parseWordForRegex(){let t=this.advance();return this.parseWordFromString(t.value,t.quoted,t.singleQuoted,!1,!1,!0,!0)}parseWordFromString(t,r=!1,s=!1,n=!1,a=!1,i=!1,l=!1){let o=ae(this,t,r,s,n,a,!1,i,l);return w.word(o)}parseCommandSubstitution(t,r){return cn(t,r,()=>new e,s=>this.error(s))}parseBacktickSubstitution(t,r,s=!1){return un(t,r,s,()=>new e,n=>this.error(n))}isDollarDparenSubshell(t,r){return ln(t,r)}parseArithmeticExpansion(t,r){let s=r+3,n=1,a=0,i=s;for(;i<t.length-1&&n>0;)t[i]==="$"&&t[i+1]==="("?t[i+2]==="("?(n++,i+=3):(a++,i+=2):t[i]==="("&&t[i+1]==="("?(n++,i+=2):t[i]===")"&&t[i+1]===")"?a>0?(a--,i++):(n--,n>0&&(i+=2)):t[i]==="("?(a++,i++):(t[i]===")"&&a>0&&a--,i++);let l=t.slice(s,i),o=this.parseArithmeticExpression(l);return{part:w.arithmeticExpansion(o),endIndex:i+2}}parseArithmeticCommand(){let t=this.expect(h.DPAREN_START),r="",s=1,n=0,a=!1,i=!1;for(;s>0&&!this.check(h.EOF);){if(a){if(a=!1,n>0){n--,r+=")";continue}if(this.check(h.RPAREN)){s--,i=!0,this.advance();continue}if(this.check(h.DPAREN_END)){s--,i=!0;continue}r+=")";continue}if(this.check(h.DPAREN_START))s++,r+="((",this.advance();else if(this.check(h.DPAREN_END))n>=2?(n-=2,r+="))",this.advance()):n===1?(n--,r+=")",a=!0,this.advance()):(s--,i=!0,s>0&&(r+="))"),this.advance());else if(this.check(h.LPAREN))n++,r+="(",this.advance();else if(this.check(h.RPAREN))n>0&&n--,r+=")",this.advance();else{let u=this.current().value,c=r.length>0?r[r.length-1]:"";r.length>0&&!r.endsWith(" ")&&!(u==="="&&/[|&^+\-*/%<>]$/.test(r))&&!(u==="<"&&c==="<")&&!(u===">"&&c===">")&&(r+=" "),r+=u,this.advance()}}i||this.expect(h.DPAREN_END);let l=this.parseArithmeticExpression(r.trim()),o=this.parseOptionalRedirections();return w.arithmeticCommand(l,o,t.line)}parseConditionalCommand(){let t=this.expect(h.DBRACK_START),r=it(this);this.expect(h.DBRACK_END);let s=this.parseOptionalRedirections();return w.conditionalCommand(r,s,t.line)}parseFunctionDef(){let t;if(this.check(h.FUNCTION)){if(this.advance(),this.check(h.NAME)||this.check(h.WORD))t=this.advance().value;else{let n=this.current();throw new G("Expected function name",n.line,n.column,n)}this.check(h.LPAREN)&&(this.advance(),this.expect(h.RPAREN))}else t=this.advance().value,t.includes("$")&&this.error(`\`${t}': not a valid identifier`),this.expect(h.LPAREN),this.expect(h.RPAREN);this.skipNewlines();let r=this.parseCompoundCommandBody({forFunctionBody:!0}),s=this.parseOptionalRedirections();return w.functionDef(t,r,s)}parseCompoundCommandBody(t){let r=t?.forFunctionBody;if(this.check(h.LBRACE))return rt(this,{skipRedirections:r});if(this.check(h.LPAREN))return nt(this,{skipRedirections:r});if(this.check(h.IF))return Xe(this,{skipRedirections:r});if(this.check(h.FOR))return Je(this,{skipRedirections:r});if(this.check(h.WHILE))return Ye(this,{skipRedirections:r});if(this.check(h.UNTIL))return et(this,{skipRedirections:r});if(this.check(h.CASE))return tt(this,{skipRedirections:r});this.error("Expected compound command for function body")}parseCompoundList(){let t=[];for(this.skipNewlines();!this.check(h.EOF,h.FI,h.ELSE,h.ELIF,h.THEN,h.DO,h.DONE,h.ESAC,h.RPAREN,h.RBRACE,h.DSEMI,h.SEMI_AND,h.SEMI_SEMI_AND)&&this.isCommandStart();){this.checkIterationLimit();let r=this.pos,s=this.parseStatement();if(s&&t.push(s),this.skipSeparators(),this.pos===r&&!s)break}return t}parseOptionalRedirections(){let t=[];for(;De(this);){this.checkIterationLimit();let r=this.pos;if(t.push(xe(this)),this.pos===r)break}return t}parseArithmeticExpression(t){return T(this,t)}};function hi(e){return new M().parse(e)}var Xr=new Map([["alnum","a-zA-Z0-9"],["alpha","a-zA-Z"],["ascii","\\x00-\\x7F"],["blank"," \\t"],["cntrl","\\x00-\\x1F\\x7F"],["digit","0-9"],["graph","!-~"],["lower","a-z"],["print"," -~"],["punct","!-/:-@\\[-`{-~"],["space"," \\t\\n\\r\\f\\v"],["upper","A-Z"],["word","a-zA-Z0-9_"],["xdigit","0-9a-fA-F"]]);function lt(e){return Xr.get(e)??""}function fn(e){let t=[],r="",s=0;for(;s<e.length;){let n=e[s];if(n==="["){for(r+=n,s++,s<e.length&&(e[s]==="!"||e[s]==="^")&&(r+=e[s],s++),s<e.length&&e[s]==="]"&&(r+=e[s],s++);s<e.length&&e[s]!=="]";){if(e[s]==="["&&s+1<e.length&&e[s+1]===":"){let a=e.indexOf(":]",s+2);if(a!==-1){r+=e.slice(s,a+2),s=a+2;continue}}if(e[s]==="\\"&&s+1<e.length){r+=e[s]+e[s+1],s+=2;continue}r+=e[s],s++}s<e.length&&e[s]==="]"&&(r+=e[s],s++)}else n===":"?(r!==""&&t.push(r),r="",s++):n==="\\"&&s+1<e.length?(r+=n+e[s+1],s+=2):(r+=n,s++)}return r!==""&&t.push(r),t}function pn(e){let t="^";for(let r=0;r<e.length;r++){let s=e[r];if(s==="*")t+="[^/]*";else if(s==="?")t+="[^/]";else if(s==="["){let n=r+1,a="[";n<e.length&&(e[n]==="^"||e[n]==="!")&&(a+="^",n++),n<e.length&&e[n]==="]"&&(a+="\\]",n++);let i=n;for(;i<e.length;){if(e[i]==="\\"&&i+1<e.length){i+=2;continue}if(e[i]==="["&&i+1<e.length&&e[i+1]===":"){let o=e.indexOf(":]",i+2);if(o!==-1){i=o+2;continue}}if(e[i]==="]")break;i++}let l=n;for(;n<e.length&&e[n]!=="]";){if(e[n]==="["&&n+1<e.length&&e[n+1]===":"){let o=e.indexOf(":]",n+2);if(o!==-1){let u=e.slice(n+2,o),c=lt(u);a+=c,n=o+2;continue}}if(e[n]==="\\"&&n+1<e.length){a+=`\\${e[n+1]}`,n+=2;continue}if(e[n]==="-"){let o=n===l,u=n+1===i;o||u?a+="\\-":a+="-"}else a+=e[n];n++}a+="]",t+=a,r=n}else if(s==="\\"&&r+1<e.length){let n=e[r+1];/[.+^${}()|\\*?[\]]/.test(n)?t+=`\\${n}`:t+=n,r++}else/[.+^${}()|]/.test(s)?t+=`\\${s}`:t+=s}return t+="$",O(t)}function ct(e,t){let r=1,s=t+1;for(;s<e.length&&r>0;){let n=e[s];if(n==="\\"){s+=2;continue}if(n==="(")r++;else if(n===")"&&(r--,r===0))return s;s++}return-1}function ut(e){let t=[],r="",s=0,n=!1,a=0;for(;a<e.length;){let i=e[a];if(i==="'"&&!n){n=!0,r+="\0QUOTE_START\0",a++;continue}if(i==="'"&&n){n=!1,r+="\0QUOTE_END\0",a++;continue}if(n){r+=i,a++;continue}if(i==="\\"){r+=i,a+1<e.length?(r+=e[a+1],a+=2):a++;continue}i==="("?(s++,r+=i):i===")"?(s--,r+=i):i==="|"&&s===0?(t.push(r),r=""):r+=i,a++}return t.push(r),t}var oe=class{fs;cwd;globignorePatterns=[];hasGlobignore=!1;globstar=!1;nullglob=!1;failglob=!1;dotglob=!1;extglob=!1;globskipdots=!0;ops={count:0};maxOps;constructor(t,r,s,n){this.fs=t,this.cwd=r,typeof n=="boolean"?(this.globstar=n,this.maxOps=1e5):n?(this.globstar=n.globstar??!1,this.nullglob=n.nullglob??!1,this.failglob=n.failglob??!1,this.dotglob=n.dotglob??!1,this.extglob=n.extglob??!1,this.globskipdots=n.globskipdots??!0,this.maxOps=n.maxGlobOperations??1e5):this.maxOps=1e5;let a=s?.get("GLOBIGNORE");a!==void 0&&a!==""&&(this.hasGlobignore=!0,this.globignorePatterns=fn(a))}checkOpsLimit(){if(++this.ops.count>this.maxOps)throw new B(`Glob operation limit exceeded (${this.maxOps})`,"glob_operations")}hasNullglob(){return this.nullglob}hasFailglob(){return this.failglob}filterGlobignore(t){return!this.hasGlobignore&&!this.globskipdots?t:t.filter(r=>{let s=r.split("/").pop()||r;if((this.hasGlobignore||this.globskipdots)&&(s==="."||s===".."))return!1;if(this.hasGlobignore){for(let n of this.globignorePatterns)if(this.matchGlobignorePattern(r,n))return!1}return!0})}matchGlobignorePattern(t,r){return pn(r).test(t)}isGlobPattern(t){return!!(t.includes("*")||t.includes("?")||/\[.*\]/.test(t)||this.extglob&&/[@*+?!]\(/.test(t))}async expandArgs(t,r){let s=t.map((i,l)=>(r?.[l]??!1)||!this.isGlobPattern(i)?null:this.expand(i)),n=await Promise.all(s.map(i=>i||Promise.resolve(null))),a=[];for(let i=0;i<t.length;i++){let l=n[i];l===null?a.push(t[i]):l.length>0?a.push(...l):a.push(t[i])}return a}async expand(t){let r;if(t.includes("**")&&this.globstar&&this.isGlobstarValid(t))r=await this.expandRecursive(t);else{let s=t.replace(/\*\*+/g,"*");r=await this.expandSimple(s)}return this.filterGlobignore(r)}isGlobstarValid(t){let r=t.split("/");for(let s of r)if(s.includes("**")&&s!=="**")return!1;return!0}hasGlobChars(t){return!!(t.includes("*")||t.includes("?")||/\[.*\]/.test(t)||this.extglob&&/[@*+?!]\(/.test(t))}async expandSimple(t){let r=t.startsWith("/"),s=t.split("/").filter(u=>u!==""),n=-1;for(let u=0;u<s.length;u++)if(this.hasGlobChars(s[u])){n=u;break}if(n===-1)return[t];let a,i;if(n===0)r?(a="/",i="/"):(a=this.cwd,i="");else{let u=s.slice(0,n);r?(a=`/${u.join("/")}`,i=`/${u.join("/")}`):(a=this.fs.resolvePath(this.cwd,u.join("/")),i=u.join("/"))}let l=s.slice(n);return(await this.expandSegments(a,i,l)).sort()}async expandSegments(t,r,s){if(this.checkOpsLimit(),s.length===0)return[r];let[n,...a]=s,i=[];try{if(this.fs.readdirWithFileTypes){this.checkOpsLimit();let l=await this.fs.readdirWithFileTypes(t),o=[],u=[...l],c=this.dotglob||this.hasGlobignore;if(n.startsWith(".")||this.dotglob){let p=l.some(g=>g.name==="."),d=l.some(g=>g.name==="..");p||u.push({name:".",isFile:!1,isDirectory:!0,isSymbolicLink:!1}),d||u.push({name:"..",isFile:!1,isDirectory:!0,isSymbolicLink:!1})}for(let p of u)if(!(p.name.startsWith(".")&&!n.startsWith(".")&&!c)&&this.matchPattern(p.name,n)){let d=t==="/"?`/${p.name}`:`${t}/${p.name}`,g;r===""?g=p.name:r==="/"?g=`/${p.name}`:g=`${r}/${p.name}`,a.length===0?o.push(Promise.resolve([g])):p.isDirectory&&o.push(this.expandSegments(d,g,a))}let f=await Promise.all(o);for(let p of f)i.push(...p)}else{this.checkOpsLimit();let l=await this.fs.readdir(t),o=[],u=[...l],c=this.dotglob||this.hasGlobignore;(n.startsWith(".")||this.dotglob)&&(l.includes(".")||u.push("."),l.includes("..")||u.push(".."));for(let p of u)if(!(p.startsWith(".")&&!n.startsWith(".")&&!c)&&this.matchPattern(p,n)){let d=t==="/"?`/${p}`:`${t}/${p}`,g;r===""?g=p:r==="/"?g=`/${p}`:g=`${r}/${p}`,a.length===0?o.push(Promise.resolve([g])):o.push((async()=>{try{if(this.checkOpsLimit(),(await this.fs.stat(d)).isDirectory)return this.expandSegments(d,g,a)}catch(m){if(m instanceof B)throw m}return[]})())}let f=await Promise.all(o);for(let p of f)i.push(...p)}}catch(l){if(l instanceof B)throw l}return i}async expandRecursive(t){let r=[],s=t.indexOf("**"),n=t.slice(0,s).replace(/\/$/,"")||".",i=t.slice(s+2).replace(/^\//,"");return i.includes("**")&&this.isGlobstarValid(i)?(await this.walkDirectoryMultiGlobstar(n,i,r),[...new Set(r)].sort()):(await this.walkDirectory(n,i,r),r.sort())}async walkDirectoryMultiGlobstar(t,r,s){this.checkOpsLimit();let n=this.fs.resolvePath(this.cwd,t);try{this.checkOpsLimit();let a=this.fs.readdirWithFileTypes?await this.fs.readdirWithFileTypes(n):null;if(a){let i=[];for(let u of a){let c=t==="."?u.name:`${t}/${u.name}`;u.isDirectory&&i.push(c)}let l=t==="."?r:`${t}/${r}`,o=await this.expandRecursive(l);s.push(...o);for(let u=0;u<i.length;u+=100){let c=i.slice(u,u+100);await Promise.all(c.map(f=>this.walkDirectoryMultiGlobstar(f,r,s)))}}else{this.checkOpsLimit();let i=await this.fs.readdir(n),l=[];for(let c of i){let f=t==="."?c:`${t}/${c}`,p=this.fs.resolvePath(this.cwd,f);try{this.checkOpsLimit(),(await this.fs.stat(p)).isDirectory&&l.push(f)}catch(d){if(d instanceof B)throw d}}let o=t==="."?r:`${t}/${r}`,u=await this.expandRecursive(o);s.push(...u);for(let c=0;c<l.length;c+=100){let f=l.slice(c,c+100);await Promise.all(f.map(p=>this.walkDirectoryMultiGlobstar(p,r,s)))}}}catch(a){if(a instanceof B)throw a}}async walkDirectory(t,r,s){this.checkOpsLimit();let n=this.fs.resolvePath(this.cwd,t);try{if(this.fs.readdirWithFileTypes){this.checkOpsLimit();let a=await this.fs.readdirWithFileTypes(n),i=[],l=[];for(let o of a){let u=t==="."?o.name:`${t}/${o.name}`;o.isDirectory?l.push(u):r&&this.matchPattern(o.name,r)&&i.push(u)}s.push(...i);for(let o=0;o<l.length;o+=100){let u=l.slice(o,o+100);await Promise.all(u.map(c=>this.walkDirectory(c,r,s)))}}else{this.checkOpsLimit();let a=await this.fs.readdir(n),i=[];for(let o=0;o<a.length;o+=100){let u=a.slice(o,o+100),c=await Promise.all(u.map(async f=>{let p=t==="."?f:`${t}/${f}`,d=this.fs.resolvePath(this.cwd,p);try{this.checkOpsLimit();let g=await this.fs.stat(d);return{name:f,path:p,isDirectory:g.isDirectory}}catch(g){if(g instanceof B)throw g;return null}}));i.push(...c.filter(f=>f!==null))}for(let o of i)!o.isDirectory&&r&&this.matchPattern(o.name,r)&&s.push(o.path);let l=i.filter(o=>o.isDirectory);for(let o=0;o<l.length;o+=100){let u=l.slice(o,o+100);await Promise.all(u.map(c=>this.walkDirectory(c.path,r,s)))}}}catch(a){if(a instanceof B)throw a}}matchPattern(t,r){return this.patternToRegex(r).test(t)}patternToRegex(t){let r=this.patternToRegexStr(t);return O(`^${r}$`)}patternToRegexStr(t){let r="",s=!1;for(let n=0;n<t.length;n++){if(t.slice(n,n+13)==="\0QUOTE_START\0"){s=!0,n+=12;continue}if(t.slice(n,n+11)==="\0QUOTE_END\0"){s=!1,n+=10;continue}let a=t[n];if(s){/[.+^${}()|\\*?[\]]/.test(a)?r+=`\\${a}`:r+=a;continue}if(this.extglob&&(a==="@"||a==="*"||a==="+"||a==="?"||a==="!")&&n+1<t.length&&t[n+1]==="("){let i=ct(t,n+1);if(i!==-1){let l=t.slice(n+2,i),o=ut(l),u=o.map(f=>this.patternToRegexStr(f)),c=u.length>0?u.join("|"):"(?:)";if(a==="@")r+=`(?:${c})`;else if(a==="*")r+=`(?:${c})*`;else if(a==="+")r+=`(?:${c})+`;else if(a==="?")r+=`(?:${c})?`;else if(a==="!")if(i<t.length-1){let p=o.map(g=>this.computePatternLength(g));if(p.every(g=>g!==null)&&p.every(g=>g===p[0])&&p[0]!==null){let g=p[0];if(g===0)r+="(?:.+)";else{let m=[];g>0&&m.push(`.{0,${g-1}}`),m.push(`.{${g+1},}`),m.push(`(?!(?:${c})).{${g}}`),r+=`(?:${m.join("|")})`}}else r+=`(?:(?!(?:${c})).)*?`}else r+=`(?!(?:${c})$).*`;n=i;continue}}if(a==="*")r+=".*";else if(a==="?")r+=".";else if(a==="["){let i=n+1,l="[";i<t.length&&(t[i]==="^"||t[i]==="!")&&(l+="^",i++),i<t.length&&t[i]==="]"&&(l+="\\]",i++);let o=i;for(;o<t.length;){if(t[o]==="\\"&&o+1<t.length){o+=2;continue}if(t[o]==="["&&o+1<t.length&&t[o+1]===":"){let c=t.indexOf(":]",o+2);if(c!==-1){o=c+2;continue}}if(t[o]==="]")break;o++}let u=i;for(;i<t.length&&t[i]!=="]";){if(t[i]==="["&&i+1<t.length&&t[i+1]===":"){let c=t.indexOf(":]",i+2);if(c!==-1){let f=t.slice(i+2,c),p=lt(f);l+=p,i=c+2;continue}}if(t[i]==="\\"&&i+1<t.length){l+=`\\${t[i+1]}`,i+=2;continue}if(t[i]==="-"){let c=i===u,f=i+1===o;c||f?l+="\\-":l+="-"}else l+=t[i];i++}l+="]",r+=l,n=i}else if(a==="\\"&&n+1<t.length){let i=t[n+1];/[.+^${}()|\\*?[\]]/.test(i)?r+=`\\${i}`:r+=i,n++}else/[.+^${}()|]/.test(a)?r+=`\\${a}`:r+=a}return r}computePatternLength(t){let r=0,s=0,n=!1;for(;s<t.length;){if(t.slice(s,s+13)==="\0QUOTE_START\0"){n=!0,s+=13;continue}if(t.slice(s,s+11)==="\0QUOTE_END\0"){n=!1,s+=11;continue}let a=t[s];if(n){r+=1,s++;continue}if((a==="@"||a==="*"||a==="+"||a==="?"||a==="!")&&s+1<t.length&&t[s+1]==="("){let i=ct(t,s+1);if(i!==-1){if(a==="@"){let l=t.slice(s+2,i),u=ut(l).map(c=>this.computePatternLength(c));if(u.every(c=>c!==null)&&u.every(c=>c===u[0])){r+=u[0],s=i+1;continue}return null}return null}}if(a==="*")return null;if(a==="?"){r+=1,s++;continue}if(a==="["){let i=t.indexOf("]",s+1);if(i!==-1){r+=1,s=i+1;continue}r+=1,s++;continue}if(a==="\\"){r+=1,s+=2;continue}r+=1,s++}return r}};function Jr(e,t,r){switch(r){case"+":return e+t;case"-":return e-t;case"*":return e*t;case"/":if(t===0)throw new C("division by 0");return Math.trunc(e/t);case"%":if(t===0)throw new C("division by 0");return e%t;case"**":if(t<0)throw new C("exponent less than 0");return e**t;case"<<":return e<<t;case">>":return e>>t;case"<":return e<t?1:0;case"<=":return e<=t?1:0;case">":return e>t?1:0;case">=":return e>=t?1:0;case"==":return e===t?1:0;case"!=":return e!==t?1:0;case"&":return e&t;case"|":return e|t;case"^":return e^t;case",":return t;default:return 0}}function hn(e,t,r){switch(r){case"=":return t;case"+=":return e+t;case"-=":return e-t;case"*=":return e*t;case"/=":return t!==0?Math.trunc(e/t):0;case"%=":return t!==0?e%t:0;case"<<=":return e<<t;case">>=":return e>>t;case"&=":return e&t;case"|=":return e|t;case"^=":return e^t;default:return t}}function Yr(e,t){switch(t){case"-":return-e;case"+":return+e;case"!":return e===0?1:0;case"~":return~e;default:return e}}async function es(e,t){let r=e.state.env.get(t);if(r!==void 0)return r;let s=e.state.env.get(`${t}_0`);return s!==void 0?s:await v(e,t)}function ts(e){if(!e)return 0;let t=Number.parseInt(e,10);if(!Number.isNaN(t)&&/^-?\d+$/.test(e.trim()))return t;let r=e.trim();if(!r)return 0;try{let s=new M,{expr:n,pos:a}=Z(s,r,0);if(a<r.length){let i=r.slice(a).trim().split(/\s+/)[0];throw new C(`${r}: syntax error in expression (error token is "${i}")`)}return n.type==="ArithNumber"?n.value:t||0}catch(s){if(s instanceof C)throw s;let n=r.split(/\s+/).slice(1)[0]||r;throw new C(`${r}: syntax error in expression (error token is "${n}")`)}}async function ft(e,t){if(!t)return 0;let r=Number.parseInt(t,10);if(!Number.isNaN(r)&&/^-?\d+$/.test(t.trim()))return r;let s=t.trim();if(!s)return 0;let n=new M,{expr:a,pos:i}=Z(n,s,0);if(i<s.length){let l=s.slice(i).trim(),o=l.split(/\s+/)[0]||l;throw new C(`syntax error in expression (error token is "${o}")`,"","")}return await R(e,a)}async function pt(e,t,r=new Set){if(r.has(t))return 0;r.add(t);let s=await es(e,t);if(!s)return 0;let n=Number.parseInt(s,10);if(!Number.isNaN(n)&&/^-?\d+$/.test(s.trim()))return n;let a=s.trim();if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(a))return await pt(e,a,r);let i=new M,{expr:l,pos:o}=Z(i,a,0);if(o<a.length){let u=a.slice(o).trim(),c=u.split(/\s+/)[0]||u;throw new C(`${a}: syntax error in expression (error token is "${c}")`)}return await R(e,l)}async function $e(e,t){if(t.startsWith("#")){let f=t.slice(1),p=f.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(p){let g=p[1],m=P(e,g);return String(m.length)}let d=e.state.env.get(f)||"";return String(d.length)}if(t.startsWith("!")){let f=t.slice(1),p=e.state.env.get(f)||"";return e.state.env.get(p)||""}let r=[":-",":=",":?",":+","-","=","?","+"],s=-1,n="";for(let f of r){let p=t.indexOf(f);p>0&&(s===-1||p<s)&&(s=p,n=f)}if(s===-1)return await v(e,t);let a=t.slice(0,s),i=t.slice(s+n.length),l=e.state.env.get(a),o=l===void 0,u=l==="",c=n.startsWith(":");switch(n){case":-":case"-":return o||c&&u?i:l||"";case":=":case"=":return o||c&&u?(e.state.env.set(a,i),i):l||"";case":+":case"+":return!(o||c&&u)?i:"";case":?":case"?":{if(o||c&&u)throw new Error(i||`${a}: parameter null or not set`);return l||""}default:return l||""}}async function R(e,t,r=!1){switch(t.type){case"ArithNumber":if(Number.isNaN(t.value))throw new C("value too great for base");return t.value;case"ArithVariable":return await pt(e,t.name);case"ArithSpecialVar":{let n=(await v(e,t.name)).trim();if(!n)return 0;let a=Number.parseInt(n,10);if(!Number.isNaN(a)&&/^-?\d+$/.test(n))return a;let i=new M,{expr:l}=Z(i,n,0);return await R(e,l)}case"ArithNested":return await R(e,t.expression);case"ArithCommandSubst":{if(e.execFn){let s=await e.execFn(t.command);s.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+s.stderr);let n=s.stdout.trim();return Number.parseInt(n,10)||0}return 0}case"ArithBracedExpansion":{let s=await $e(e,t.content);return Number.parseInt(s,10)||0}case"ArithDynamicBase":{let s=await $e(e,t.baseExpr),n=Number.parseInt(s,10);if(n<2||n>64)return 0;let a=`${n}#${t.value}`;return me(a)}case"ArithDynamicNumber":{let n=await $e(e,t.prefix)+t.suffix;return me(n)}case"ArithArrayElement":{let s=e.state.associativeArrays?.has(t.array),n=async a=>{let i=e.state.env.get(a);return i!==void 0?await ft(e,i):0};if(t.stringKey!==void 0)return await n(`${t.array}_${t.stringKey}`);if(s&&t.index?.type==="ArithVariable"&&!t.index.hasDollarPrefix)return await n(`${t.array}_${t.index.name}`);if(s&&t.index?.type==="ArithVariable"&&t.index.hasDollarPrefix){let a=await v(e,t.index.name);return await n(`${t.array}_${a}`)}if(t.index){let a=await R(e,t.index,r);if(a<0){let o=P(e,t.array),u=e.state.currentLine;if(o.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${u}: ${t.array}: bad array subscript
|
|
48
|
+
`&&(l+=c),i+=2):(l+=e[i],i++)}else l+=e[i],i++;i>=e.length&&n("unexpected EOF while looking for matching ``'");let u=s().parse(l);return{part:w.commandSubstitution(u,!0),endIndex:i+1}}var M=class e{tokens=[];pos=0;pendingHeredocs=[];parseIterations=0;parseDepth=0;_input="";getInput(){return this._input}checkIterationLimit(){if(this.parseIterations++,this.parseIterations>Zt)throw new z("Maximum parse iterations exceeded (possible infinite loop)",this.current().line,this.current().column)}enterDepth(){if(this.parseDepth++,this.parseDepth>Ue)throw new z(`Maximum parser nesting depth exceeded (${Ue})`,this.current().line,this.current().column);return()=>{this.parseDepth--}}parse(t){if(t.length>Ze)throw new z(`Input too large: ${t.length} bytes exceeds limit of ${Ze}`,1,1);this._input=t;let r=new De(t);if(this.tokens=r.tokenize(),this.tokens.length>Ge)throw new z(`Too many tokens: ${this.tokens.length} exceeds limit of ${Ge}`,1,1);return this.pos=0,this.pendingHeredocs=[],this.parseIterations=0,this.parseDepth=0,this.parseScript()}parseTokens(t){return this.tokens=t,this.pos=0,this.pendingHeredocs=[],this.parseIterations=0,this.parseDepth=0,this.parseScript()}current(){return this.tokens[this.pos]||this.tokens[this.tokens.length-1]}peek(t=0){return this.tokens[this.pos+t]||this.tokens[this.tokens.length-1]}advance(){let t=this.current();return this.pos<this.tokens.length-1&&this.pos++,t}getPos(){return this.pos}check(t,r,s,n,...a){let i=this.tokens[this.pos]?.type;return i===t||r!==void 0&&i===r||s!==void 0&&i===s||n!==void 0&&i===n?!0:a.length>0?a.includes(i):!1}expect(t,r){if(this.check(t))return this.advance();let s=this.current();throw new z(r||`Expected ${t}, got ${s.type}`,s.line,s.column,s)}error(t){let r=this.current();throw new z(t,r.line,r.column,r)}skipNewlines(){for(;this.check(h.NEWLINE,h.COMMENT);)this.check(h.NEWLINE)?(this.advance(),this.processHeredocs()):this.advance()}skipSeparators(t=!0){for(;;){if(this.check(h.NEWLINE)){this.advance(),this.processHeredocs();continue}if(this.check(h.SEMICOLON,h.COMMENT)){this.advance();continue}if(t&&this.check(h.DSEMI,h.SEMI_AND,h.SEMI_SEMI_AND)){this.advance();continue}break}}addPendingHeredoc(t,r,s,n){this.pendingHeredocs.push({redirect:t,delimiter:r,stripTabs:s,quoted:n})}processHeredocs(){for(let t of this.pendingHeredocs)if(this.check(h.HEREDOC_CONTENT)){let r=this.advance(),s;t.quoted?s=w.word([w.literal(r.value)]):s=this.parseWordFromString(r.value,!1,!1,!1,!0),t.redirect.target=w.hereDoc(t.delimiter,s,t.stripTabs,t.quoted)}this.pendingHeredocs=[]}isStatementEnd(){return this.check(h.EOF,h.NEWLINE,h.SEMICOLON,h.AMP,h.AND_AND,h.OR_OR,h.RPAREN,h.RBRACE,h.DSEMI,h.SEMI_AND,h.SEMI_SEMI_AND)}isCommandStart(){let t=this.current().type;return t===h.WORD||t===h.NAME||t===h.NUMBER||t===h.ASSIGNMENT_WORD||t===h.IF||t===h.FOR||t===h.WHILE||t===h.UNTIL||t===h.CASE||t===h.LPAREN||t===h.LBRACE||t===h.DPAREN_START||t===h.DBRACK_START||t===h.FUNCTION||t===h.BANG||t===h.TIME||t===h.IN||t===h.LESS||t===h.GREAT||t===h.DLESS||t===h.DGREAT||t===h.LESSAND||t===h.GREATAND||t===h.LESSGREAT||t===h.DLESSDASH||t===h.CLOBBER||t===h.TLESS||t===h.AND_GREAT||t===h.AND_DGREAT}parseScript(){let t=[],s=0;for(this.skipNewlines();!this.check(h.EOF);){s++,s>1e4&&this.error("Parser stuck: too many iterations (>10000)");let n=this.checkUnexpectedToken();if(n){t.push(n),this.skipSeparators(!1);continue}let a=this.pos,i=this.parseStatement();i&&t.push(i),this.skipSeparators(!1),this.check(h.DSEMI,h.SEMI_AND,h.SEMI_SEMI_AND)&&this.error(`syntax error near unexpected token \`${this.current().value}'`),this.pos===a&&!this.check(h.EOF)&&this.advance()}return w.script(t)}checkUnexpectedToken(){let t=this.current().type,r=this.current().value;if((t===h.DO||t===h.DONE||t===h.THEN||t===h.ELSE||t===h.ELIF||t===h.FI||t===h.ESAC)&&this.error(`syntax error near unexpected token \`${r}'`),t===h.RBRACE||t===h.RPAREN){let s=`syntax error near unexpected token \`${r}'`;return this.advance(),w.statement([w.pipeline([w.simpleCommand(null,[],[],[])])],[],!1,{message:s,token:r})}return(t===h.DSEMI||t===h.SEMI_AND||t===h.SEMI_SEMI_AND)&&this.error(`syntax error near unexpected token \`${r}'`),t===h.SEMICOLON&&this.error(`syntax error near unexpected token \`${r}'`),(t===h.PIPE||t===h.PIPE_AMP)&&this.error(`syntax error near unexpected token \`${r}'`),null}parseStatement(){if(this.skipNewlines(),!this.isCommandStart())return null;let t=this.current().start,r=[],s=[],n=!1,a=this.parsePipeline();for(r.push(a);this.check(h.AND_AND,h.OR_OR);){let o=this.advance();s.push(o.type===h.AND_AND?"&&":"||"),this.skipNewlines();let u=this.parsePipeline();r.push(u)}this.check(h.AMP)&&(this.advance(),n=!0);let i=this.pos>0?this.tokens[this.pos-1].end:t,l=this._input.slice(t,i);return w.statement(r,s,n,void 0,l)}parsePipeline(){let t=!1,r=!1;this.check(h.TIME)&&(this.advance(),t=!0,this.check(h.WORD,h.NAME)&&this.current().value==="-p"&&(this.advance(),r=!0));let s=0;for(;this.check(h.BANG);)this.advance(),s++;let n=s%2===1,a=[],i=[],l=this.parseCommand();for(a.push(l);this.check(h.PIPE,h.PIPE_AMP);){let o=this.advance();this.skipNewlines(),i.push(o.type===h.PIPE_AMP);let u=this.parseCommand();a.push(u)}return w.pipeline(a,n,t,r,i.length>0?i:void 0)}parseCommand(){return this.check(h.IF)?Je(this):this.check(h.FOR)?Ye(this):this.check(h.WHILE)?et(this):this.check(h.UNTIL)?tt(this):this.check(h.CASE)?nt(this):this.check(h.LPAREN)?rt(this):this.check(h.LBRACE)?st(this):this.check(h.DPAREN_START)?this.dparenClosesWithSpacedParens()?this.parseNestedSubshellsFromDparen():this.parseArithmeticCommand():this.check(h.DBRACK_START)?this.parseConditionalCommand():this.check(h.FUNCTION)?this.parseFunctionDef():this.check(h.NAME,h.WORD)&&this.peek(1).type===h.LPAREN&&this.peek(2).type===h.RPAREN?this.parseFunctionDef():rn(this)}dparenClosesWithSpacedParens(){let t=1,r=1;for(;r<this.tokens.length-this.pos;){let s=this.peek(r);if(s.type===h.EOF)return!1;if(s.type===h.DPAREN_START||s.type===h.LPAREN)t++;else if(s.type===h.DPAREN_END){if(t-=2,t<=0)return!1}else if(s.type===h.RPAREN&&(t--,t===0&&this.peek(r+1).type===h.RPAREN))return!0;r++}return!1}parseNestedSubshellsFromDparen(){this.advance();let t=this.parseCompoundList();this.expect(h.RPAREN),this.expect(h.RPAREN);let r=this.parseOptionalRedirections(),s=w.subshell(t,[]);return w.subshell([w.statement([w.pipeline([s],!1,!1,!1)])],r)}isWord(){let t=this.current().type;return t===h.WORD||t===h.NAME||t===h.NUMBER||t===h.IF||t===h.FOR||t===h.WHILE||t===h.UNTIL||t===h.CASE||t===h.FUNCTION||t===h.ELSE||t===h.ELIF||t===h.FI||t===h.THEN||t===h.DO||t===h.DONE||t===h.ESAC||t===h.IN||t===h.SELECT||t===h.TIME||t===h.COPROC||t===h.BANG}parseWord(){let t=this.advance();return this.parseWordFromString(t.value,t.quoted,t.singleQuoted)}parseWordNoBraceExpansion(){let t=this.advance();return this.parseWordFromString(t.value,t.quoted,t.singleQuoted,!1,!1,!0)}parseWordForRegex(){let t=this.advance();return this.parseWordFromString(t.value,t.quoted,t.singleQuoted,!1,!1,!0,!0)}parseWordFromString(t,r=!1,s=!1,n=!1,a=!1,i=!1,l=!1){let o=ae(this,t,r,s,n,a,!1,i,l);return w.word(o)}parseCommandSubstitution(t,r){return un(t,r,()=>new e,s=>this.error(s))}parseBacktickSubstitution(t,r,s=!1){return fn(t,r,s,()=>new e,n=>this.error(n))}isDollarDparenSubshell(t,r){return cn(t,r)}parseArithmeticExpansion(t,r){let s=r+3,n=1,a=0,i=s;for(;i<t.length-1&&n>0;)t[i]==="$"&&t[i+1]==="("?t[i+2]==="("?(n++,i+=3):(a++,i+=2):t[i]==="("&&t[i+1]==="("?(n++,i+=2):t[i]===")"&&t[i+1]===")"?a>0?(a--,i++):(n--,n>0&&(i+=2)):t[i]==="("?(a++,i++):(t[i]===")"&&a>0&&a--,i++);let l=t.slice(s,i),o=this.parseArithmeticExpression(l);return{part:w.arithmeticExpansion(o),endIndex:i+2}}parseArithmeticCommand(){let t=this.expect(h.DPAREN_START),r="",s=1,n=0,a=!1,i=!1;for(;s>0&&!this.check(h.EOF);){if(a){if(a=!1,n>0){n--,r+=")";continue}if(this.check(h.RPAREN)){s--,i=!0,this.advance();continue}if(this.check(h.DPAREN_END)){s--,i=!0;continue}r+=")";continue}if(this.check(h.DPAREN_START))s++,r+="((",this.advance();else if(this.check(h.DPAREN_END))n>=2?(n-=2,r+="))",this.advance()):n===1?(n--,r+=")",a=!0,this.advance()):(s--,i=!0,s>0&&(r+="))"),this.advance());else if(this.check(h.LPAREN))n++,r+="(",this.advance();else if(this.check(h.RPAREN))n>0&&n--,r+=")",this.advance();else{let u=this.current().value,c=r.length>0?r[r.length-1]:"";r.length>0&&!r.endsWith(" ")&&!(u==="="&&/[|&^+\-*/%<>]$/.test(r))&&!(u==="<"&&c==="<")&&!(u===">"&&c===">")&&(r+=" "),r+=u,this.advance()}}i||this.expect(h.DPAREN_END);let l=this.parseArithmeticExpression(r.trim()),o=this.parseOptionalRedirections();return w.arithmeticCommand(l,o,t.line)}parseConditionalCommand(){let t=this.expect(h.DBRACK_START),r=at(this);this.expect(h.DBRACK_END);let s=this.parseOptionalRedirections();return w.conditionalCommand(r,s,t.line)}parseFunctionDef(){let t;if(this.check(h.FUNCTION)){if(this.advance(),this.check(h.NAME)||this.check(h.WORD))t=this.advance().value;else{let n=this.current();throw new z("Expected function name",n.line,n.column,n)}this.check(h.LPAREN)&&(this.advance(),this.expect(h.RPAREN))}else t=this.advance().value,t.includes("$")&&this.error(`\`${t}': not a valid identifier`),this.expect(h.LPAREN),this.expect(h.RPAREN);this.skipNewlines();let r=this.parseCompoundCommandBody({forFunctionBody:!0}),s=this.parseOptionalRedirections();return w.functionDef(t,r,s)}parseCompoundCommandBody(t){let r=t?.forFunctionBody;if(this.check(h.LBRACE))return st(this,{skipRedirections:r});if(this.check(h.LPAREN))return rt(this,{skipRedirections:r});if(this.check(h.IF))return Je(this,{skipRedirections:r});if(this.check(h.FOR))return Ye(this,{skipRedirections:r});if(this.check(h.WHILE))return et(this,{skipRedirections:r});if(this.check(h.UNTIL))return tt(this,{skipRedirections:r});if(this.check(h.CASE))return nt(this,{skipRedirections:r});this.error("Expected compound command for function body")}parseCompoundList(){let t=this.enterDepth(),r=[];for(this.skipNewlines();!this.check(h.EOF,h.FI,h.ELSE,h.ELIF,h.THEN,h.DO,h.DONE,h.ESAC,h.RPAREN,h.RBRACE,h.DSEMI,h.SEMI_AND,h.SEMI_SEMI_AND)&&this.isCommandStart();){this.checkIterationLimit();let s=this.pos,n=this.parseStatement();if(n&&r.push(n),this.skipSeparators(),this.pos===s&&!n)break}return t(),r}parseOptionalRedirections(){let t=[];for(;ve(this);){this.checkIterationLimit();let r=this.pos;if(t.push(xe(this)),this.pos===r)break}return t}parseArithmeticExpression(t){return T(this,t)}};function di(e){return new M().parse(e)}var Jr=new Map([["alnum","a-zA-Z0-9"],["alpha","a-zA-Z"],["ascii","\\x00-\\x7F"],["blank"," \\t"],["cntrl","\\x00-\\x1F\\x7F"],["digit","0-9"],["graph","!-~"],["lower","a-z"],["print"," -~"],["punct","!-/:-@\\[-`{-~"],["space"," \\t\\n\\r\\f\\v"],["upper","A-Z"],["word","a-zA-Z0-9_"],["xdigit","0-9a-fA-F"]]);function ct(e){return Jr.get(e)??""}function pn(e){let t=[],r="",s=0;for(;s<e.length;){let n=e[s];if(n==="["){for(r+=n,s++,s<e.length&&(e[s]==="!"||e[s]==="^")&&(r+=e[s],s++),s<e.length&&e[s]==="]"&&(r+=e[s],s++);s<e.length&&e[s]!=="]";){if(e[s]==="["&&s+1<e.length&&e[s+1]===":"){let a=e.indexOf(":]",s+2);if(a!==-1){r+=e.slice(s,a+2),s=a+2;continue}}if(e[s]==="\\"&&s+1<e.length){r+=e[s]+e[s+1],s+=2;continue}r+=e[s],s++}s<e.length&&e[s]==="]"&&(r+=e[s],s++)}else n===":"?(r!==""&&t.push(r),r="",s++):n==="\\"&&s+1<e.length?(r+=n+e[s+1],s+=2):(r+=n,s++)}return r!==""&&t.push(r),t}function hn(e){let t="^";for(let r=0;r<e.length;r++){let s=e[r];if(s==="*")t+="[^/]*";else if(s==="?")t+="[^/]";else if(s==="["){let n=r+1,a="[";n<e.length&&(e[n]==="^"||e[n]==="!")&&(a+="^",n++),n<e.length&&e[n]==="]"&&(a+="\\]",n++);let i=n;for(;i<e.length;){if(e[i]==="\\"&&i+1<e.length){i+=2;continue}if(e[i]==="["&&i+1<e.length&&e[i+1]===":"){let o=e.indexOf(":]",i+2);if(o!==-1){i=o+2;continue}}if(e[i]==="]")break;i++}let l=n;for(;n<e.length&&e[n]!=="]";){if(e[n]==="["&&n+1<e.length&&e[n+1]===":"){let o=e.indexOf(":]",n+2);if(o!==-1){let u=e.slice(n+2,o),c=ct(u);a+=c,n=o+2;continue}}if(e[n]==="\\"&&n+1<e.length){a+=`\\${e[n+1]}`,n+=2;continue}if(e[n]==="-"){let o=n===l,u=n+1===i;o||u?a+="\\-":a+="-"}else a+=e[n];n++}a+="]",t+=a,r=n}else if(s==="\\"&&r+1<e.length){let n=e[r+1];/[.+^${}()|\\*?[\]]/.test(n)?t+=`\\${n}`:t+=n,r++}else/[.+^${}()|]/.test(s)?t+=`\\${s}`:t+=s}return t+="$",O(t)}function ut(e,t){let r=1,s=t+1;for(;s<e.length&&r>0;){let n=e[s];if(n==="\\"){s+=2;continue}if(n==="(")r++;else if(n===")"&&(r--,r===0))return s;s++}return-1}function ft(e){let t=[],r="",s=0,n=!1,a=0;for(;a<e.length;){let i=e[a];if(i==="'"&&!n){n=!0,r+="\0QUOTE_START\0",a++;continue}if(i==="'"&&n){n=!1,r+="\0QUOTE_END\0",a++;continue}if(n){r+=i,a++;continue}if(i==="\\"){r+=i,a+1<e.length?(r+=e[a+1],a+=2):a++;continue}i==="("?(s++,r+=i):i===")"?(s--,r+=i):i==="|"&&s===0?(t.push(r),r=""):r+=i,a++}return t.push(r),t}var oe=class{fs;cwd;globignorePatterns=[];hasGlobignore=!1;globstar=!1;nullglob=!1;failglob=!1;dotglob=!1;extglob=!1;globskipdots=!0;ops={count:0};maxOps;constructor(t,r,s,n){this.fs=t,this.cwd=r,typeof n=="boolean"?(this.globstar=n,this.maxOps=1e5):n?(this.globstar=n.globstar??!1,this.nullglob=n.nullglob??!1,this.failglob=n.failglob??!1,this.dotglob=n.dotglob??!1,this.extglob=n.extglob??!1,this.globskipdots=n.globskipdots??!0,this.maxOps=n.maxGlobOperations??1e5):this.maxOps=1e5;let a=s?.get("GLOBIGNORE");a!==void 0&&a!==""&&(this.hasGlobignore=!0,this.globignorePatterns=pn(a))}checkOpsLimit(){if(++this.ops.count>this.maxOps)throw new B(`Glob operation limit exceeded (${this.maxOps})`,"glob_operations")}hasNullglob(){return this.nullglob}hasFailglob(){return this.failglob}filterGlobignore(t){return!this.hasGlobignore&&!this.globskipdots?t:t.filter(r=>{let s=r.split("/").pop()||r;if((this.hasGlobignore||this.globskipdots)&&(s==="."||s===".."))return!1;if(this.hasGlobignore){for(let n of this.globignorePatterns)if(this.matchGlobignorePattern(r,n))return!1}return!0})}matchGlobignorePattern(t,r){return hn(r).test(t)}isGlobPattern(t){return!!(t.includes("*")||t.includes("?")||/\[.*\]/.test(t)||this.extglob&&/[@*+?!]\(/.test(t))}async expandArgs(t,r){let s=t.map((i,l)=>(r?.[l]??!1)||!this.isGlobPattern(i)?null:this.expand(i)),n=await Promise.all(s.map(i=>i||Promise.resolve(null))),a=[];for(let i=0;i<t.length;i++){let l=n[i];l===null?a.push(t[i]):l.length>0?a.push(...l):a.push(t[i])}return a}async expand(t){let r;if(t.includes("**")&&this.globstar&&this.isGlobstarValid(t))r=await this.expandRecursive(t);else{let s=t.replace(/\*\*+/g,"*");r=await this.expandSimple(s)}return this.filterGlobignore(r)}isGlobstarValid(t){let r=t.split("/");for(let s of r)if(s.includes("**")&&s!=="**")return!1;return!0}hasGlobChars(t){return!!(t.includes("*")||t.includes("?")||/\[.*\]/.test(t)||this.extglob&&/[@*+?!]\(/.test(t))}async expandSimple(t){let r=t.startsWith("/"),s=t.split("/").filter(u=>u!==""),n=-1;for(let u=0;u<s.length;u++)if(this.hasGlobChars(s[u])){n=u;break}if(n===-1)return[t];let a,i;if(n===0)r?(a="/",i="/"):(a=this.cwd,i="");else{let u=s.slice(0,n);r?(a=`/${u.join("/")}`,i=`/${u.join("/")}`):(a=this.fs.resolvePath(this.cwd,u.join("/")),i=u.join("/"))}let l=s.slice(n);return(await this.expandSegments(a,i,l)).sort()}async expandSegments(t,r,s){if(this.checkOpsLimit(),s.length===0)return[r];let[n,...a]=s,i=[];try{if(this.fs.readdirWithFileTypes){this.checkOpsLimit();let l=await this.fs.readdirWithFileTypes(t),o=[],u=[...l],c=this.dotglob||this.hasGlobignore;if(n.startsWith(".")||this.dotglob){let p=l.some(g=>g.name==="."),d=l.some(g=>g.name==="..");p||u.push({name:".",isFile:!1,isDirectory:!0,isSymbolicLink:!1}),d||u.push({name:"..",isFile:!1,isDirectory:!0,isSymbolicLink:!1})}for(let p of u)if(!(p.name.startsWith(".")&&!n.startsWith(".")&&!c)&&this.matchPattern(p.name,n)){let d=t==="/"?`/${p.name}`:`${t}/${p.name}`,g;r===""?g=p.name:r==="/"?g=`/${p.name}`:g=`${r}/${p.name}`,a.length===0?o.push(Promise.resolve([g])):p.isDirectory&&o.push(this.expandSegments(d,g,a))}let f=await Promise.all(o);for(let p of f)i.push(...p)}else{this.checkOpsLimit();let l=await this.fs.readdir(t),o=[],u=[...l],c=this.dotglob||this.hasGlobignore;(n.startsWith(".")||this.dotglob)&&(l.includes(".")||u.push("."),l.includes("..")||u.push(".."));for(let p of u)if(!(p.startsWith(".")&&!n.startsWith(".")&&!c)&&this.matchPattern(p,n)){let d=t==="/"?`/${p}`:`${t}/${p}`,g;r===""?g=p:r==="/"?g=`/${p}`:g=`${r}/${p}`,a.length===0?o.push(Promise.resolve([g])):o.push((async()=>{try{if(this.checkOpsLimit(),(await this.fs.stat(d)).isDirectory)return this.expandSegments(d,g,a)}catch(m){if(m instanceof B)throw m}return[]})())}let f=await Promise.all(o);for(let p of f)i.push(...p)}}catch(l){if(l instanceof B)throw l}return i}async expandRecursive(t){let r=[],s=t.indexOf("**"),n=t.slice(0,s).replace(/\/$/,"")||".",i=t.slice(s+2).replace(/^\//,"");return i.includes("**")&&this.isGlobstarValid(i)?(await this.walkDirectoryMultiGlobstar(n,i,r),[...new Set(r)].sort()):(await this.walkDirectory(n,i,r),r.sort())}async walkDirectoryMultiGlobstar(t,r,s){this.checkOpsLimit();let n=this.fs.resolvePath(this.cwd,t);try{this.checkOpsLimit();let a=this.fs.readdirWithFileTypes?await this.fs.readdirWithFileTypes(n):null;if(a){let i=[];for(let u of a){let c=t==="."?u.name:`${t}/${u.name}`;u.isDirectory&&i.push(c)}let l=t==="."?r:`${t}/${r}`,o=await this.expandRecursive(l);s.push(...o);for(let u=0;u<i.length;u+=100){let c=i.slice(u,u+100);await Promise.all(c.map(f=>this.walkDirectoryMultiGlobstar(f,r,s)))}}else{this.checkOpsLimit();let i=await this.fs.readdir(n),l=[];for(let c of i){let f=t==="."?c:`${t}/${c}`,p=this.fs.resolvePath(this.cwd,f);try{this.checkOpsLimit(),(await this.fs.stat(p)).isDirectory&&l.push(f)}catch(d){if(d instanceof B)throw d}}let o=t==="."?r:`${t}/${r}`,u=await this.expandRecursive(o);s.push(...u);for(let c=0;c<l.length;c+=100){let f=l.slice(c,c+100);await Promise.all(f.map(p=>this.walkDirectoryMultiGlobstar(p,r,s)))}}}catch(a){if(a instanceof B)throw a}}async walkDirectory(t,r,s){this.checkOpsLimit();let n=this.fs.resolvePath(this.cwd,t);try{if(this.fs.readdirWithFileTypes){this.checkOpsLimit();let a=await this.fs.readdirWithFileTypes(n),i=[],l=[];for(let o of a){let u=t==="."?o.name:`${t}/${o.name}`;o.isDirectory?l.push(u):r&&this.matchPattern(o.name,r)&&i.push(u)}s.push(...i);for(let o=0;o<l.length;o+=100){let u=l.slice(o,o+100);await Promise.all(u.map(c=>this.walkDirectory(c,r,s)))}}else{this.checkOpsLimit();let a=await this.fs.readdir(n),i=[];for(let o=0;o<a.length;o+=100){let u=a.slice(o,o+100),c=await Promise.all(u.map(async f=>{let p=t==="."?f:`${t}/${f}`,d=this.fs.resolvePath(this.cwd,p);try{this.checkOpsLimit();let g=await this.fs.stat(d);return{name:f,path:p,isDirectory:g.isDirectory}}catch(g){if(g instanceof B)throw g;return null}}));i.push(...c.filter(f=>f!==null))}for(let o of i)!o.isDirectory&&r&&this.matchPattern(o.name,r)&&s.push(o.path);let l=i.filter(o=>o.isDirectory);for(let o=0;o<l.length;o+=100){let u=l.slice(o,o+100);await Promise.all(u.map(c=>this.walkDirectory(c.path,r,s)))}}}catch(a){if(a instanceof B)throw a}}matchPattern(t,r){return this.patternToRegex(r).test(t)}patternToRegex(t){let r=this.patternToRegexStr(t);return O(`^${r}$`)}patternToRegexStr(t){let r="",s=!1;for(let n=0;n<t.length;n++){if(t.slice(n,n+13)==="\0QUOTE_START\0"){s=!0,n+=12;continue}if(t.slice(n,n+11)==="\0QUOTE_END\0"){s=!1,n+=10;continue}let a=t[n];if(s){/[.+^${}()|\\*?[\]]/.test(a)?r+=`\\${a}`:r+=a;continue}if(this.extglob&&(a==="@"||a==="*"||a==="+"||a==="?"||a==="!")&&n+1<t.length&&t[n+1]==="("){let i=ut(t,n+1);if(i!==-1){let l=t.slice(n+2,i),o=ft(l),u=o.map(f=>this.patternToRegexStr(f)),c=u.length>0?u.join("|"):"(?:)";if(a==="@")r+=`(?:${c})`;else if(a==="*")r+=`(?:${c})*`;else if(a==="+")r+=`(?:${c})+`;else if(a==="?")r+=`(?:${c})?`;else if(a==="!")if(i<t.length-1){let p=o.map(g=>this.computePatternLength(g));if(p.every(g=>g!==null)&&p.every(g=>g===p[0])&&p[0]!==null){let g=p[0];if(g===0)r+="(?:.+)";else{let m=[];g>0&&m.push(`.{0,${g-1}}`),m.push(`.{${g+1},}`),m.push(`(?!(?:${c})).{${g}}`),r+=`(?:${m.join("|")})`}}else r+=`(?:(?!(?:${c})).)*?`}else r+=`(?!(?:${c})$).*`;n=i;continue}}if(a==="*")r+=".*";else if(a==="?")r+=".";else if(a==="["){let i=n+1,l="[";i<t.length&&(t[i]==="^"||t[i]==="!")&&(l+="^",i++),i<t.length&&t[i]==="]"&&(l+="\\]",i++);let o=i;for(;o<t.length;){if(t[o]==="\\"&&o+1<t.length){o+=2;continue}if(t[o]==="["&&o+1<t.length&&t[o+1]===":"){let c=t.indexOf(":]",o+2);if(c!==-1){o=c+2;continue}}if(t[o]==="]")break;o++}let u=i;for(;i<t.length&&t[i]!=="]";){if(t[i]==="["&&i+1<t.length&&t[i+1]===":"){let c=t.indexOf(":]",i+2);if(c!==-1){let f=t.slice(i+2,c),p=ct(f);l+=p,i=c+2;continue}}if(t[i]==="\\"&&i+1<t.length){l+=`\\${t[i+1]}`,i+=2;continue}if(t[i]==="-"){let c=i===u,f=i+1===o;c||f?l+="\\-":l+="-"}else l+=t[i];i++}l+="]",r+=l,n=i}else if(a==="\\"&&n+1<t.length){let i=t[n+1];/[.+^${}()|\\*?[\]]/.test(i)?r+=`\\${i}`:r+=i,n++}else/[.+^${}()|]/.test(a)?r+=`\\${a}`:r+=a}return r}computePatternLength(t){let r=0,s=0,n=!1;for(;s<t.length;){if(t.slice(s,s+13)==="\0QUOTE_START\0"){n=!0,s+=13;continue}if(t.slice(s,s+11)==="\0QUOTE_END\0"){n=!1,s+=11;continue}let a=t[s];if(n){r+=1,s++;continue}if((a==="@"||a==="*"||a==="+"||a==="?"||a==="!")&&s+1<t.length&&t[s+1]==="("){let i=ut(t,s+1);if(i!==-1){if(a==="@"){let l=t.slice(s+2,i),u=ft(l).map(c=>this.computePatternLength(c));if(u.every(c=>c!==null)&&u.every(c=>c===u[0])){r+=u[0],s=i+1;continue}return null}return null}}if(a==="*")return null;if(a==="?"){r+=1,s++;continue}if(a==="["){let i=t.indexOf("]",s+1);if(i!==-1){r+=1,s=i+1;continue}r+=1,s++;continue}if(a==="\\"){r+=1,s+=2;continue}r+=1,s++}return r}};function Yr(e,t,r){switch(r){case"+":return e+t;case"-":return e-t;case"*":return e*t;case"/":if(t===0)throw new C("division by 0");return Math.trunc(e/t);case"%":if(t===0)throw new C("division by 0");return e%t;case"**":if(t<0)throw new C("exponent less than 0");return e**t;case"<<":return e<<t;case">>":return e>>t;case"<":return e<t?1:0;case"<=":return e<=t?1:0;case">":return e>t?1:0;case">=":return e>=t?1:0;case"==":return e===t?1:0;case"!=":return e!==t?1:0;case"&":return e&t;case"|":return e|t;case"^":return e^t;case",":return t;default:return 0}}function dn(e,t,r){switch(r){case"=":return t;case"+=":return e+t;case"-=":return e-t;case"*=":return e*t;case"/=":return t!==0?Math.trunc(e/t):0;case"%=":return t!==0?e%t:0;case"<<=":return e<<t;case">>=":return e>>t;case"&=":return e&t;case"|=":return e|t;case"^=":return e^t;default:return t}}function es(e,t){switch(t){case"-":return-e;case"+":return+e;case"!":return e===0?1:0;case"~":return~e;default:return e}}async function ts(e,t){let r=e.state.env.get(t);if(r!==void 0)return r;let s=e.state.env.get(`${t}_0`);return s!==void 0?s:await D(e,t)}function ns(e){if(!e)return 0;let t=Number.parseInt(e,10);if(!Number.isNaN(t)&&/^-?\d+$/.test(e.trim()))return t;let r=e.trim();if(!r)return 0;try{let s=new M,{expr:n,pos:a}=G(s,r,0);if(a<r.length){let i=r.slice(a).trim().split(/\s+/)[0];throw new C(`${r}: syntax error in expression (error token is "${i}")`)}return n.type==="ArithNumber"?n.value:t||0}catch(s){if(s instanceof C)throw s;let n=r.split(/\s+/).slice(1)[0]||r;throw new C(`${r}: syntax error in expression (error token is "${n}")`)}}async function pt(e,t){if(!t)return 0;let r=Number.parseInt(t,10);if(!Number.isNaN(r)&&/^-?\d+$/.test(t.trim()))return r;let s=t.trim();if(!s)return 0;let n=new M,{expr:a,pos:i}=G(n,s,0);if(i<s.length){let l=s.slice(i).trim(),o=l.split(/\s+/)[0]||l;throw new C(`syntax error in expression (error token is "${o}")`,"","")}return await R(e,a)}async function ht(e,t,r=new Set){if(r.has(t))return 0;r.add(t);let s=await ts(e,t);if(!s)return 0;let n=Number.parseInt(s,10);if(!Number.isNaN(n)&&/^-?\d+$/.test(s.trim()))return n;let a=s.trim();if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(a))return await ht(e,a,r);let i=new M,{expr:l,pos:o}=G(i,a,0);if(o<a.length){let u=a.slice(o).trim(),c=u.split(/\s+/)[0]||u;throw new C(`${a}: syntax error in expression (error token is "${c}")`)}return await R(e,l)}async function $e(e,t){if(t.startsWith("#")){let f=t.slice(1),p=f.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(p){let g=p[1],m=P(e,g);return String(m.length)}let d=e.state.env.get(f)||"";return String(d.length)}if(t.startsWith("!")){let f=t.slice(1),p=e.state.env.get(f)||"";return e.state.env.get(p)||""}let r=[":-",":=",":?",":+","-","=","?","+"],s=-1,n="";for(let f of r){let p=t.indexOf(f);p>0&&(s===-1||p<s)&&(s=p,n=f)}if(s===-1)return await D(e,t);let a=t.slice(0,s),i=t.slice(s+n.length),l=e.state.env.get(a),o=l===void 0,u=l==="",c=n.startsWith(":");switch(n){case":-":case"-":return o||c&&u?i:l||"";case":=":case"=":return o||c&&u?(e.state.env.set(a,i),i):l||"";case":+":case"+":return!(o||c&&u)?i:"";case":?":case"?":{if(o||c&&u)throw new Error(i||`${a}: parameter null or not set`);return l||""}default:return l||""}}async function R(e,t,r=!1){switch(t.type){case"ArithNumber":if(Number.isNaN(t.value))throw new C("value too great for base");return t.value;case"ArithVariable":return await ht(e,t.name);case"ArithSpecialVar":{let n=(await D(e,t.name)).trim();if(!n)return 0;let a=Number.parseInt(n,10);if(!Number.isNaN(a)&&/^-?\d+$/.test(n))return a;let i=new M,{expr:l}=G(i,n,0);return await R(e,l)}case"ArithNested":return await R(e,t.expression);case"ArithCommandSubst":{if(e.execFn){let s=await e.execFn(t.command);s.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+s.stderr);let n=s.stdout.trim();return Number.parseInt(n,10)||0}return 0}case"ArithBracedExpansion":{let s=await $e(e,t.content);return Number.parseInt(s,10)||0}case"ArithDynamicBase":{let s=await $e(e,t.baseExpr),n=Number.parseInt(s,10);if(n<2||n>64)return 0;let a=`${n}#${t.value}`;return me(a)}case"ArithDynamicNumber":{let n=await $e(e,t.prefix)+t.suffix;return me(n)}case"ArithArrayElement":{let s=e.state.associativeArrays?.has(t.array),n=async a=>{let i=e.state.env.get(a);return i!==void 0?await pt(e,i):0};if(t.stringKey!==void 0)return await n(`${t.array}_${t.stringKey}`);if(s&&t.index?.type==="ArithVariable"&&!t.index.hasDollarPrefix)return await n(`${t.array}_${t.index.name}`);if(s&&t.index?.type==="ArithVariable"&&t.index.hasDollarPrefix){let a=await D(e,t.index.name);return await n(`${t.array}_${a}`)}if(t.index){let a=await R(e,t.index,r);if(a<0){let o=P(e,t.array),u=e.state.currentLine;if(o.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${u}: ${t.array}: bad array subscript
|
|
49
49
|
`,0;let f=Math.max(...o.map(([p])=>typeof p=="number"?p:0))+1+a;if(f<0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${u}: ${t.array}: bad array subscript
|
|
50
|
-
`,0;a=f}let i=`${t.array}_${a}`,l=e.state.env.get(i);if(l!==void 0)return
|
|
50
|
+
`,0;a=f}let i=`${t.array}_${a}`,l=e.state.env.get(i);if(l!==void 0)return pt(e,l);if(a===0){let o=e.state.env.get(t.array);if(o!==void 0)return pt(e,o)}if(e.state.options.nounset&&!Array.from(e.state.env.keys()).some(u=>u===t.array||u.startsWith(`${t.array}_`)))throw new H(`${t.array}[${a}]`);return 0}return 0}case"ArithDoubleSubscript":throw new C("double subscript","","");case"ArithNumberSubscript":throw new C(`${t.number}${t.errorToken}: syntax error: invalid arithmetic operator (error token is "${t.errorToken}")`);case"ArithSyntaxError":throw new C(t.message,"","",!0);case"ArithSingleQuote":{if(r)throw new C(`syntax error: operand expected (error token is "'${t.content}'")`);return t.value}case"ArithBinary":{if(t.operator==="||")return await R(e,t.left,r)||await R(e,t.right,r)?1:0;if(t.operator==="&&")return await R(e,t.left,r)&&await R(e,t.right,r)?1:0;let s=await R(e,t.left,r),n=await R(e,t.right,r);return Yr(s,n,t.operator)}case"ArithUnary":{let s=await R(e,t.operand,r);if(t.operator==="++"||t.operator==="--"){if(t.operand.type==="ArithVariable"){let n=t.operand.name,a=Number.parseInt(await D(e,n),10)||0,i=t.operator==="++"?a+1:a-1;return e.state.env.set(n,String(i)),t.prefix?i:a}if(t.operand.type==="ArithArrayElement"){let n=t.operand.array,a=e.state.associativeArrays?.has(n),i;if(t.operand.stringKey!==void 0)i=`${n}_${t.operand.stringKey}`;else if(a&&t.operand.index?.type==="ArithVariable"&&!t.operand.index.hasDollarPrefix)i=`${n}_${t.operand.index.name}`;else if(a&&t.operand.index?.type==="ArithVariable"&&t.operand.index.hasDollarPrefix){let u=await D(e,t.operand.index.name);i=`${n}_${u}`}else if(t.operand.index){let u=await R(e,t.operand.index,r);i=`${n}_${u}`}else return s;let l=Number.parseInt(e.state.env.get(i)||"0",10)||0,o=t.operator==="++"?l+1:l-1;return e.state.env.set(i,String(o)),t.prefix?o:l}if(t.operand.type==="ArithConcat"){let n="";for(let a of t.operand.parts)n+=await he(e,a,r);if(n&&/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n)){let a=Number.parseInt(e.state.env.get(n)||"0",10)||0,i=t.operator==="++"?a+1:a-1;return e.state.env.set(n,String(i)),t.prefix?i:a}}if(t.operand.type==="ArithDynamicElement"){let n="";if(t.operand.nameExpr.type==="ArithConcat")for(let a of t.operand.nameExpr.parts)n+=await he(e,a,r);else t.operand.nameExpr.type==="ArithVariable"&&(n=t.operand.nameExpr.hasDollarPrefix?await D(e,t.operand.nameExpr.name):t.operand.nameExpr.name);if(n&&/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n)){let a=await R(e,t.operand.subscript,r),i=`${n}_${a}`,l=Number.parseInt(e.state.env.get(i)||"0",10)||0,o=t.operator==="++"?l+1:l-1;return e.state.env.set(i,String(o)),t.prefix?o:l}}return s}return es(s,t.operator)}case"ArithTernary":return await R(e,t.condition,r)?await R(e,t.consequent,r):await R(e,t.alternate,r);case"ArithAssignment":{let s=t.variable,n=s;if(t.stringKey!==void 0)n=`${s}_${t.stringKey}`;else if(t.subscript){let o=e.state.associativeArrays?.has(s);if(o&&t.subscript.type==="ArithVariable"&&!t.subscript.hasDollarPrefix)n=`${s}_${t.subscript.name}`;else if(o&&t.subscript.type==="ArithVariable"&&t.subscript.hasDollarPrefix){let u=await D(e,t.subscript.name);n=`${s}_${u||"\\"}`}else if(o){let u=await R(e,t.subscript,r);n=`${s}_${u}`}else{let u=await R(e,t.subscript,r);if(u<0){let c=P(e,s);c.length>0&&(u=Math.max(...c.map(([p])=>typeof p=="number"?p:0))+1+u)}n=`${s}_${u}`}}let a=Number.parseInt(e.state.env.get(n)||"0",10)||0,i=await R(e,t.value,r),l=dn(a,i,t.operator);return e.state.env.set(n,String(l)),l}case"ArithGroup":return await R(e,t.expression,r);case"ArithConcat":{let s="";for(let n of t.parts)s+=await he(e,n,r);return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s)?await ht(e,s):Number.parseInt(s,10)||0}case"ArithDynamicAssignment":{let s="";if(t.target.type==="ArithConcat")for(let o of t.target.parts)s+=await he(e,o,r);else t.target.type==="ArithVariable"&&(s=t.target.hasDollarPrefix?await D(e,t.target.name):t.target.name);if(!s||!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s))return 0;let n=s;if(t.subscript){let o=await R(e,t.subscript,r);n=`${s}_${o}`}let a=Number.parseInt(e.state.env.get(n)||"0",10)||0,i=await R(e,t.value,r),l=dn(a,i,t.operator);return e.state.env.set(n,String(l)),l}case"ArithDynamicElement":{let s="";if(t.nameExpr.type==="ArithConcat")for(let l of t.nameExpr.parts)s+=await he(e,l,r);else t.nameExpr.type==="ArithVariable"&&(s=t.nameExpr.hasDollarPrefix?await D(e,t.nameExpr.name):t.nameExpr.name);if(!s||!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s))return 0;let n=await R(e,t.subscript,r),a=`${s}_${n}`,i=e.state.env.get(a);return i!==void 0?ns(i):0}default:return 0}}async function he(e,t,r=!1){switch(t.type){case"ArithNumber":return String(t.value);case"ArithSingleQuote":return String(await R(e,t,r));case"ArithVariable":return t.hasDollarPrefix?await D(e,t.name):t.name;case"ArithSpecialVar":return await D(e,t.name);case"ArithBracedExpansion":return await $e(e,t.content);case"ArithCommandSubst":return e.execFn?(await e.execFn(t.command)).stdout.trim():"0";case"ArithConcat":{let s="";for(let n of t.parts)s+=await he(e,n,r);return s}default:return String(await R(e,t,r))}}function dt(e){for(let t=0;t<e.length;t++){if(e[t]==="\\"){t++;continue}if(e[t]==="$"){let r=e[t+1];if(r==="{"||r&&/[a-zA-Z_]/.test(r))return!0}}return!1}function rs(e){if(!e.operation)return!1;let t=e.operation,r;if((t.type==="DefaultValue"||t.type==="AssignDefault"||t.type==="UseAlternative"||t.type==="ErrorIfUnset")&&(r=t.word?.parts),!r)return!1;for(let s of r)if(s.type==="DoubleQuoted"||s.type==="SingleQuoted")return!0;return!1}function mn(e){if(!e.operation)return!1;let t=e.operation,r;if((t.type==="DefaultValue"||t.type==="AssignDefault"||t.type==="UseAlternative"||t.type==="ErrorIfUnset")&&(r=t.word?.parts),!r||r.length===0)return!1;for(let s of r)if(s.type!=="DoubleQuoted"&&s.type!=="SingleQuoted")return!1;return!0}function ye(e){let t=!1,r=!1,s=!1,n=!1,a=!1,i=!1,l=!1;for(let o of e){if((o.type==="SingleQuoted"||o.type==="DoubleQuoted")&&(t=!0,o.type==="DoubleQuoted"))for(let u of o.parts)u.type==="ParameterExpansion"&&(u.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/)&&(!u.operation||u.operation.type==="PatternRemoval"||u.operation.type==="PatternReplacement")&&(n=!0),(u.operation?.type==="VarNamePrefix"||u.operation?.type==="ArrayKeys")&&(i=!0),u.operation?.type==="Indirection"&&(l=!0));o.type==="CommandSubstitution"&&(r=!0),o.type==="ParameterExpansion"&&(a=!0,(o.parameter==="@"||o.parameter==="*")&&(s=!0),rs(o)&&(t=!0),(o.operation?.type==="VarNamePrefix"||o.operation?.type==="ArrayKeys")&&(i=!0),o.operation?.type==="Indirection"&&(l=!0)),o.type==="Glob"&&dt(o.pattern)&&(a=!0)}return{hasQuoted:t,hasCommandSub:r,hasArrayVar:s,hasArrayAtExpansion:n,hasParamExpansion:a,hasVarNamePrefixExpansion:i,hasIndirection:l}}var gn="5.1.0(1)-release",xi="Linux version 5.15.0-generic (just-bash) #1 SMP PREEMPT";function Ee(){return{pid:process.pid,ppid:process.ppid,uid:process.getuid?.()??1e3,gid:process.getgid?.()??1e3}}function $i(){let{pid:e,ppid:t,uid:r,gid:s}=Ee();return`Name: bash
|
|
51
51
|
State: R (running)
|
|
52
52
|
Pid: ${e}
|
|
53
53
|
PPid: ${t}
|
|
54
54
|
Uid: ${r} ${r} ${r} ${r}
|
|
55
55
|
Gid: ${s} ${s} ${s} ${s}
|
|
56
|
-
`}function
|
|
56
|
+
`}function mt(e,t){let r=`${t}_`,s=[];for(let n of e.state.env.keys())if(n.startsWith(r)){let a=n.slice(r.length),i=Number.parseInt(a,10);!Number.isNaN(i)&&String(i)===a&&s.push(i)}return s.sort((n,a)=>n-a)}function Ci(e,t){let r=`${t}_`;for(let s of e.state.env.keys())s.startsWith(r)&&e.state.env.delete(s)}function gt(e,t){let r=`${t}_`,s=`${t}__length`,n=[];for(let a of e.state.env.keys())if(a!==s&&a.startsWith(r)){let i=a.slice(r.length);if(i.startsWith("_length"))continue;n.push(i)}return n.sort()}function _e(e){return e.startsWith("'")&&e.endsWith("'")||e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e}function Oi(e){if(e.parts.length<2)return null;let t=e.parts[0],r=e.parts[1];if(t.type!=="Glob"||!t.pattern.startsWith("["))return null;let s,n=r,a=1;if(r.type==="Literal"&&r.value.startsWith("]")){let f=r.value.slice(1);if(f.startsWith("+=")||f.startsWith("="))s=t.pattern.slice(1);else if(f===""){if(e.parts.length<3)return null;let p=e.parts[2];if(p.type!=="Literal"||!p.value.startsWith("=")&&!p.value.startsWith("+="))return null;s=t.pattern.slice(1),n=p,a=2}else return null}else if(t.pattern==="["&&(r.type==="DoubleQuoted"||r.type==="SingleQuoted")){if(e.parts.length<3)return null;let f=e.parts[2];if(f.type!=="Literal"||!f.value.startsWith("]=")&&!f.value.startsWith("]+="))return null;if(r.type==="SingleQuoted")s=r.value;else{s="";for(let p of r.parts)(p.type==="Literal"||p.type==="Escaped")&&(s+=p.value)}n=f,a=2}else if(t.pattern.endsWith("]")){if(r.type!=="Literal"||!r.value.startsWith("=")&&!r.value.startsWith("+="))return null;s=t.pattern.slice(1,-1)}else return null;s=_e(s);let i;if(n.type!=="Literal")return null;n.value.startsWith("]=")||n.value.startsWith("]+=")?i=n.value.slice(1):i=n.value;let l=i.startsWith("+=");if(!l&&!i.startsWith("="))return null;let o=[],u=l?2:1,c=i.slice(u);c&&o.push({type:"Literal",value:c});for(let f=a+1;f<e.parts.length;f++){let p=e.parts[f];p.type==="BraceExpansion"?o.push({type:"Literal",value:ss(p)}):o.push(p)}return{key:s,valueParts:o,append:l}}function ss(e){return`{${e.items.map(r=>{if(r.type==="Range"){let s=r.startStr??String(r.start),n=r.endStr??String(r.end),a=`${s}..${n}`;return r.step&&(a+=`..${r.step}`),a}return yn(r.word)}).join(",")}}`}function yn(e){let t="";for(let r of e.parts)switch(r.type){case"Literal":t+=r.value;break;case"Glob":t+=r.pattern;break;case"SingleQuoted":t+=r.value;break;case"DoubleQuoted":for(let s of r.parts)(s.type==="Literal"||s.type==="Escaped")&&(t+=s.value);break;case"Escaped":t+=r.value;break;case"BraceExpansion":t+="{",t+=r.items.map(s=>s.type==="Range"?`${s.startStr}..${s.endStr}${s.step?`..${s.step}`:""}`:yn(s.word)).join(","),t+="}";break;case"TildeExpansion":t+="~",r.user&&(t+=r.user);break}return t}function W(e){return e.get("IFS")??`
|
|
57
57
|
`}function V(e){return e.get("IFS")===""}function Ce(e){let t=W(e);if(t==="")return!0;for(let r of t)if(r!==" "&&r!==" "&&r!==`
|
|
58
|
-
`)return!1;return!0}function
|
|
59
|
-
`?"\\n":t).join("")}function N(e){let t=e.get("IFS");return t===void 0?" ":t[0]||""}var
|
|
60
|
-
`;function
|
|
58
|
+
`)return!1;return!0}function En(e){return e.split("").map(t=>/[\\^$.*+?()[\]{}|-]/.test(t)?`\\${t}`:t===" "?"\\t":t===`
|
|
59
|
+
`?"\\n":t).join("")}function N(e){let t=e.get("IFS");return t===void 0?" ":t[0]||""}var is=`
|
|
60
|
+
`;function as(e){return is.includes(e)}function yt(e){let t=new Set,r=new Set;for(let s of e)as(s)?t.add(s):r.add(s);return{whitespace:t,nonWhitespace:r}}function Wi(e,t,r,s){if(t==="")return e===""?{words:[],wordStarts:[]}:{words:[e],wordStarts:[0]};let{whitespace:n,nonWhitespace:a}=yt(t),i=[],l=[],o=0;for(;o<e.length&&n.has(e[o]);)o++;if(o>=e.length)return{words:[],wordStarts:[]};if(a.has(e[o]))for(i.push(""),l.push(o),o++;o<e.length&&n.has(e[o]);)o++;for(;o<e.length&&!(r!==void 0&&i.length>=r);){let u=o;for(l.push(u);o<e.length;){let c=e[o];if(!s&&c==="\\"){o++,o<e.length&&o++;continue}if(n.has(c)||a.has(c))break;o++}if(i.push(e.substring(u,o)),o>=e.length)break;for(;o<e.length&&n.has(e[o]);)o++;if(o<e.length&&a.has(e[o])){for(o++;o<e.length&&n.has(e[o]);)o++;for(;o<e.length&&a.has(e[o])&&!(r!==void 0&&i.length>=r);)for(i.push(""),l.push(o),o++;o<e.length&&n.has(e[o]);)o++}}return{words:i,wordStarts:l}}function Oe(e,t){if(t==="")return{words:e?[e]:[],hadLeadingDelimiter:!1,hadTrailingDelimiter:!1};if(e==="")return{words:[],hadLeadingDelimiter:!1,hadTrailingDelimiter:!1};let{whitespace:r,nonWhitespace:s}=yt(t),n=[],a=0,i=!1,l=!1,o=a;for(;a<e.length&&r.has(e[a]);)a++;if(a>o&&(i=!0),a>=e.length)return{words:[],hadLeadingDelimiter:!0,hadTrailingDelimiter:!0};if(s.has(e[a]))for(n.push(""),a++;a<e.length&&r.has(e[a]);)a++;for(;a<e.length;){let u=a;for(;a<e.length;){let f=e[a];if(r.has(f)||s.has(f))break;a++}if(n.push(e.substring(u,a)),a>=e.length){l=!1;break}let c=a;for(;a<e.length&&r.has(e[a]);)a++;if(a<e.length&&s.has(e[a])){for(a++;a<e.length&&r.has(e[a]);)a++;for(;a<e.length&&s.has(e[a]);)for(n.push(""),a++;a<e.length&&r.has(e[a]);)a++}a>=e.length&&a>c&&(l=!0)}return{words:n,hadLeadingDelimiter:i,hadTrailingDelimiter:l}}function x(e,t){return Oe(e,t).words}function os(e,t){for(let r of e)if(t.has(r))return!0;return!1}function Ti(e,t,r){if(t==="")return e;let{whitespace:s,nonWhitespace:n}=yt(t),a=e.length;for(;a>0&&s.has(e[a-1]);){if(!r&&a>=2){let l=0,o=a-2;for(;o>=0&&e[o]==="\\";)l++,o--;if(l%2===1)break}a--}let i=e.substring(0,a);if(i.length>=1&&n.has(i[i.length-1])){if(!r&&i.length>=2){let o=0,u=i.length-2;for(;u>=0&&i[u]==="\\";)o++,u--;if(o%2===1)return i}let l=i.substring(0,i.length-1);if(!os(l,n))return l}return i}function L(e,t){return e.state.namerefs?.has(t)??!1}function Vi(e,t){e.state.namerefs??=new Set,e.state.namerefs.add(t)}function qi(e,t){e.state.namerefs?.delete(t),e.state.boundNamerefs?.delete(t),e.state.invalidNamerefs?.delete(t)}function Bi(e,t){e.state.invalidNamerefs??=new Set,e.state.invalidNamerefs.add(t)}function An(e,t){return e.state.invalidNamerefs?.has(t)??!1}function Fi(e,t){e.state.boundNamerefs??=new Set,e.state.boundNamerefs.add(t)}function ls(e,t){let r=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(r){let n=r[1],a=Array.from(e.state.env.keys()).some(l=>l.startsWith(`${n}_`)&&!l.includes("__")),i=e.state.associativeArrays?.has(n)??!1;return a||i}return Array.from(e.state.env.keys()).some(n=>n.startsWith(`${t}_`)&&!n.includes("__"))?!0:e.state.env.has(t)}function fe(e,t,r=100){if(!L(e,t)||An(e,t))return t;let s=new Set,n=t;for(;r-- >0;){if(s.has(n))return;if(s.add(n),!L(e,n))return n;let a=e.state.env.get(n);if(a===void 0||a===""||!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(a))return n;n=a}}function Ae(e,t){if(L(e,t))return e.state.env.get(t)}function Qi(e,t,r,s=100){if(!L(e,t)||An(e,t))return t;let n=new Set,a=t;for(;s-- >0;){if(n.has(a))return;if(n.add(a),!L(e,a))return a;let i=e.state.env.get(a);if(i===void 0||i==="")return r!==void 0?/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r)&&ls(e,r)?a:null:a;if(!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(i))return a;a=i}}function cs(e,t){let r=t.replace(/\$\{([a-zA-Z_][a-zA-Z0-9_]*)\}/g,(s,n)=>e.state.env.get(n)??"");return r=r.replace(/\$([a-zA-Z_][a-zA-Z0-9_]*)/g,(s,n)=>e.state.env.get(n)??""),r}function P(e,t){return t==="FUNCNAME"?(e.state.funcNameStack??[]).map((a,i)=>[i,a]):t==="BASH_LINENO"?(e.state.callLineStack??[]).map((a,i)=>[i,String(a)]):t==="BASH_SOURCE"?(e.state.sourceStack??[]).map((a,i)=>[i,a]):e.state.associativeArrays?.has(t)?gt(e,t).map(a=>[a,e.state.env.get(`${t}_${a}`)??""]):mt(e,t).map(n=>[n,e.state.env.get(`${t}_${n}`)??""])}function Se(e,t){return t==="FUNCNAME"?(e.state.funcNameStack?.length??0)>0:t==="BASH_LINENO"?(e.state.callLineStack?.length??0)>0:t==="BASH_SOURCE"?(e.state.sourceStack?.length??0)>0:e.state.associativeArrays?.has(t)?gt(e,t).length>0:mt(e,t).length>0}async function D(e,t,r=!0,s=!1){switch(t){case"?":return String(e.state.lastExitCode);case"$":return String(process.pid);case"#":return e.state.env.get("#")||"0";case"@":return e.state.env.get("@")||"";case"_":return e.state.lastArg;case"-":{let i="";return i+="h",e.state.options.errexit&&(i+="e"),e.state.options.noglob&&(i+="f"),e.state.options.nounset&&(i+="u"),e.state.options.verbose&&(i+="v"),e.state.options.xtrace&&(i+="x"),i+="B",e.state.options.noclobber&&(i+="C"),i+="s",i}case"*":{let i=Number.parseInt(e.state.env.get("#")||"0",10);if(i===0)return"";let l=[];for(let o=1;o<=i;o++)l.push(e.state.env.get(String(o))||"");return l.join(N(e.state.env))}case"0":return e.state.env.get("0")||"bash";case"PWD":return e.state.env.get("PWD")??"";case"OLDPWD":return e.state.env.get("OLDPWD")??"";case"PPID":{let{ppid:i}=Ee();return String(i)}case"UID":{let{uid:i}=Ee();return String(i)}case"EUID":return String(process.geteuid?.()??Ee().uid);case"RANDOM":return String(Math.floor(Math.random()*32768));case"SECONDS":return String(Math.floor((Date.now()-e.state.startTime)/1e3));case"BASH_VERSION":return gn;case"!":return String(e.state.lastBackgroundPid);case"BASHPID":return String(e.state.bashPid);case"LINENO":return String(e.state.currentLine);case"FUNCNAME":{let i=e.state.funcNameStack?.[0];if(i!==void 0)return i;if(r&&e.state.options.nounset)throw new H("FUNCNAME");return""}case"BASH_LINENO":{let i=e.state.callLineStack?.[0];if(i!==void 0)return String(i);if(r&&e.state.options.nounset)throw new H("BASH_LINENO");return""}case"BASH_SOURCE":{let i=e.state.sourceStack?.[0];if(i!==void 0)return i;if(r&&e.state.options.nounset)throw new H("BASH_SOURCE");return""}}if(/^[a-zA-Z_][a-zA-Z0-9_]*\[\]$/.test(t))throw new re(`\${${t}}`);let n=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(n){let i=n[1],l=n[2];if(L(e,i)){let f=fe(e,i);if(f&&f!==i){if(f.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/))return"";i=f}}if(l==="@"||l==="*"){let f=P(e,i);if(f.length>0)return f.map(([,d])=>d).join(" ");let p=e.state.env.get(i);return p!==void 0?p:""}if(i==="FUNCNAME"){let f=Number.parseInt(l,10);return!Number.isNaN(f)&&f>=0?e.state.funcNameStack?.[f]??"":""}if(i==="BASH_LINENO"){let f=Number.parseInt(l,10);if(!Number.isNaN(f)&&f>=0){let p=e.state.callLineStack?.[f];return p!==void 0?String(p):""}return""}if(i==="BASH_SOURCE"){let f=Number.parseInt(l,10);return!Number.isNaN(f)&&f>=0?e.state.sourceStack?.[f]??"":""}if(e.state.associativeArrays?.has(i)){let f=_e(l);f=cs(e,f);let p=e.state.env.get(`${i}_${f}`);if(p===void 0&&r&&e.state.options.nounset)throw new H(`${i}[${l}]`);return p||""}let u;if(/^-?\d+$/.test(l))u=Number.parseInt(l,10);else try{let f=new M,p=T(f,l);u=await R(e,p.expression)}catch{let f=e.state.env.get(l);u=f?Number.parseInt(f,10):0,Number.isNaN(u)&&(u=0)}if(u<0){let f=P(e,i),p=e.state.currentLine;if(f.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${p}: ${i}: bad array subscript
|
|
61
61
|
`,"";let g=Math.max(...f.map(([E])=>typeof E=="number"?E:0))+1+u;return g<0?(e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${p}: ${i}: bad array subscript
|
|
62
|
-
`,""):e.state.env.get(`${i}_${g}`)||""}let c=e.state.env.get(`${i}_${u}`);if(c!==void 0)return c;if(u===0){let f=e.state.env.get(i);if(f!==void 0)return f}if(r&&e.state.options.nounset)throw new H(`${i}[${u}]`);return""}if(/^[1-9][0-9]*$/.test(t)){let i=e.state.env.get(t);if(i===void 0&&r&&e.state.options.nounset)throw new H(t);return i||""}if(L(e,t)){let i=fe(e,t);if(i===void 0)return"";if(i!==t)return await v(e,i,r,s);let l=e.state.env.get(t);if((l===void 0||l==="")&&r&&e.state.options.nounset)throw new H(t);return l||""}let a=e.state.env.get(t);if(a!==void 0)return e.state.tempEnvBindings?.some(i=>i.has(t))&&(e.state.accessedTempEnvVars=e.state.accessedTempEnvVars||new Set,e.state.accessedTempEnvVars.add(t)),a;if(Se(e,t)){let i=e.state.env.get(`${t}_0`);return i!==void 0?i:""}if(r&&e.state.options.nounset)throw new H(t);return""}async function te(e,t){if(new Set(["?","$","#","_","-","0","PPID","UID","EUID","RANDOM","SECONDS","BASH_VERSION","!","BASHPID","LINENO"]).has(t))return!0;if(t==="@"||t==="*")return Number.parseInt(e.state.env.get("#")||"0",10)>0;if(t==="PWD"||t==="OLDPWD")return e.state.env.has(t);let s=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(s){let n=s[1],a=s[2];if(L(e,n)){let o=fe(e,n);if(o&&o!==n){if(o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/))return!1;n=o}}if(a==="@"||a==="*")return P(e,n).length>0?!0:e.state.env.has(n);if(e.state.associativeArrays?.has(n)){let o=_e(a);return e.state.env.has(`${n}_${o}`)}let l;if(/^-?\d+$/.test(a))l=Number.parseInt(a,10);else try{let o=new M,u=T(o,a);l=await R(e,u.expression)}catch{let o=e.state.env.get(a);l=o?Number.parseInt(o,10):0,Number.isNaN(l)&&(l=0)}if(l<0){let o=P(e,n);if(o.length===0)return!1;let c=Math.max(...o.map(([f])=>typeof f=="number"?f:0))+1+l;return c<0?!1:e.state.env.has(`${n}_${c}`)}return e.state.env.has(`${n}_${l}`)}if(L(e,t)){let n=fe(e,t);return n===void 0||n===t?e.state.env.has(t):te(e,n)}return!!(e.state.env.has(t)||Se(e,t))}async function An(e,t){let r="",s=0;for(;s<t.length;){if(t[s]==="$"){if(t[s+1]==="{"){let n=1,a=s+2;for(;a<t.length&&n>0;)t[a]==="{"?n++:t[a]==="}"&&n--,a++;r+=t.slice(s,a),s=a;continue}if(t[s+1]==="("){let n=1,a=s+2;for(;a<t.length&&n>0;)t[a]==="("?n++:t[a]===")"&&n--,a++;r+=t.slice(s,a),s=a;continue}if(/[a-zA-Z_]/.test(t[s+1]||"")){let n=s+1;for(;n<t.length&&/[a-zA-Z0-9_]/.test(t[n]);)n++;let a=t.slice(s+1,n),i=await v(e,a);r+=i,s=n;continue}if(/[0-9]/.test(t[s+1]||"")){let n=s+1;for(;n<t.length&&/[0-9]/.test(t[n]);)n++;let a=t.slice(s+1,n),i=await v(e,a);r+=i,s=n;continue}if(/[*@#?\-!$]/.test(t[s+1]||"")){let n=t[s+1],a=await v(e,n);r+=a,s+=2;continue}}if(t[s]==='"'){for(r+='"',s++;s<t.length&&t[s]!=='"';)if(t[s]==="$"&&/[a-zA-Z_]/.test(t[s+1]||"")){let n=s+1;for(;n<t.length&&/[a-zA-Z0-9_]/.test(t[n]);)n++;let a=t.slice(s+1,n),i=await v(e,a);r+=i,s=n}else t[s]==="\\"?(r+=t[s],s++,s<t.length&&(r+=t[s],s++)):(r+=t[s],s++);s<t.length&&(r+='"',s++);continue}r+=t[s],s++}return r}async function yt(e,t){let r=t,s=t.startsWith('"')&&t.endsWith('"'),n=t.startsWith("'")&&t.endsWith("'");if((s||n)&&(r=t.slice(1,-1)),n)return r;let a="",i=0;for(;i<r.length;)if(r[i]==="$")if(r[i+1]==="("){let l=1,o=i+2;for(;o<r.length&&l>0;)r[o]==="("&&r[o-1]==="$"||r[o]==="("?l++:r[o]===")"&&l--,o++;let u=r.slice(i+2,o-1);if(e.execFn){let c=await e.execFn(u);a+=c.stdout.replace(/\n+$/,""),c.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+c.stderr)}i=o}else if(r[i+1]==="{"){let l=1,o=i+2;for(;o<r.length&&l>0;)r[o]==="{"?l++:r[o]==="}"&&l--,o++;let u=r.slice(i+2,o-1),c=await v(e,u);a+=c,i=o}else if(/[a-zA-Z_]/.test(r[i+1]||"")){let l=i+1;for(;l<r.length&&/[a-zA-Z0-9_]/.test(r[l]);)l++;let o=r.slice(i+1,l),u=await v(e,o);a+=u,i=l}else a+=r[i],i++;else if(r[i]==="`"){let l=i+1;for(;l<r.length&&r[l]!=="`";)l++;let o=r.slice(i+1,l);if(e.execFn){let u=await e.execFn(o);a+=u.stdout.replace(/\n+$/,""),u.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+u.stderr)}i=l+1}else a+=r[i],i++;return a}var Le=1e4;function cs(e,t,r,s,n){let a=r??1;a===0&&(a=1);let i=Math.abs(a),l=[],o=0;s?.match(/^-?0\d/)&&(o=Math.max(o,s.replace(/^-/,"").length)),n?.match(/^-?0\d/)&&(o=Math.max(o,n.replace(/^-/,"").length));let u=c=>{if(o>0){let f=c<0,p=String(Math.abs(c)).padStart(o,"0");return f?`-${p}`:p}return String(c)};if(e<=t)for(let c=e,f=0;c<=t&&f<Le;c+=i,f++)l.push(u(c));else for(let c=e,f=0;c>=t&&f<Le;c-=i,f++)l.push(u(c));return l}function us(e,t,r){let s=r??1;s===0&&(s=1);let n=e.charCodeAt(0),a=t.charCodeAt(0),i=Math.abs(s),l=e>="A"&&e<="Z",o=e>="a"&&e<="z",u=t>="A"&&t<="Z",c=t>="a"&&t<="z";if(l&&c||o&&u){let p=r!==void 0?`..${r}`:"";throw new Rt(`{${e}..${t}${p}}: invalid sequence`)}let f=[];if(n<=a)for(let p=n,d=0;p<=a&&d<Le;p+=i,d++)f.push(String.fromCharCode(p));else for(let p=n,d=0;p>=a&&d<Le;p-=i,d++)f.push(String.fromCharCode(p));return f}function Et(e,t,r,s,n){let a=r!==void 0?`..${r}`:"";return typeof e=="number"&&typeof t=="number"?{expanded:cs(e,t,r,s,n),literal:`{${e}..${t}${a}}`}:typeof e=="string"&&typeof t=="string"?{expanded:us(e,t,r),literal:`{${e}..${t}${a}}`}:{expanded:null,literal:`{${e}..${t}${a}}`}}function Sn(e){if(e.statements.length!==1)return null;let t=e.statements[0];if(t.operators.length!==0||t.pipelines.length!==1)return null;let r=t.pipelines[0];if(r.negated||r.commands.length!==1)return null;let s=r.commands[0];if(s.type!=="SimpleCommand")return null;let n=s;if(n.name!==null||n.args.length!==0||n.assignments.length!==0||n.redirections.length!==1)return null;let a=n.redirections[0];return a.operator!=="<"||a.target.type!=="Word"?null:{target:a.target}}function ne(e,t){return!!(/[*?[]/.test(e)||t&&/[@*+?!]\(/.test(e))}function At(e){let t="",r=0;for(;r<e.length;)e[r]==="\\"&&r+1<e.length?(t+=e[r+1],r+=2):(t+=e[r],r++);return t}function K(e){return e.replace(/([*?[\]\\()|])/g,"\\$1")}function St(e){return e.replace(/[\\^$.*+?()[\]{}|]/g,"\\$&")}function I(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function k(e,t,r=!1){let s="",n=0;for(;n<e.length;){let a=e[n];if(r&&(a==="@"||a==="*"||a==="+"||a==="?"||a==="!")&&n+1<e.length&&e[n+1]==="("){let i=fs(e,n+1);if(i!==-1){let l=e.slice(n+2,i),u=ps(l).map(f=>k(f,t,r)),c=u.length>0?u.join("|"):"(?:)";a==="@"?s+=`(?:${c})`:a==="*"?s+=`(?:${c})*`:a==="+"?s+=`(?:${c})+`:a==="?"?s+=`(?:${c})?`:a==="!"&&(s+=`(?!(?:${c})$).*`),n=i+1;continue}}if(a==="\\")if(n+1<e.length){let i=e[n+1];/[\\^$.|+(){}[\]*?]/.test(i)?s+=`\\${i}`:s+=i,n+=2}else s+="\\\\",n++;else if(a==="*")s+=t?".*":".*?",n++;else if(a==="?")s+=".",n++;else if(a==="["){let i=hs(e,n);if(i===-1)s+="\\[",n++;else{let l=e.slice(n+1,i);s+=ds(l),n=i+1}}else/[\^$.|+(){}]/.test(a)?(s+=`\\${a}`,n++):(s+=a,n++)}return s}function fs(e,t){let r=1,s=t+1;for(;s<e.length&&r>0;){let n=e[s];if(n==="\\"){s+=2;continue}if(n==="(")r++;else if(n===")"&&(r--,r===0))return s;s++}return-1}function ps(e){let t=[],r="",s=0,n=0;for(;n<e.length;){let a=e[n];if(a==="\\"){r+=a,n+1<e.length?(r+=e[n+1],n+=2):n++;continue}a==="("?(s++,r+=a):a===")"?(s--,r+=a):a==="|"&&s===0?(t.push(r),r=""):r+=a,n++}return t.push(r),t}function hs(e,t){let r=t+1;for(r<e.length&&e[r]==="^"&&r++,r<e.length&&e[r]==="]"&&r++;r<e.length;){if(e[r]==="\\"&&r+1<e.length){r+=2;continue}if(e[r]==="]")return r;if(e[r]==="'"){let s=e.indexOf("'",r+1);if(s!==-1){r=s+1;continue}}if(e[r]==="["&&r+1<e.length&&e[r+1]===":"){let s=e.indexOf(":]",r+2);if(s!==-1){r=s+2;continue}}r++}return-1}function ds(e){let t="[",r=0;for((e[0]==="^"||e[0]==="!")&&(t+="^",r++);r<e.length;){if(e[r]==="'"){let n=e.indexOf("'",r+1);if(n!==-1){let a=e.slice(r+1,n);for(let i of a)i==="\\"?t+="\\\\":i==="]"?t+="\\]":i==="^"&&t==="["?t+="\\^":t+=i;r=n+1;continue}}if(e[r]==="["&&r+1<e.length&&e[r+1]===":"){let n=e.indexOf(":]",r+2);if(n!==-1){let a=e.slice(r+2,n);t+=gs(a),r=n+2;continue}}let s=e[r];s==="\\"?r+1<e.length?(t+=`\\${e[r+1]}`,r+=2):(t+="\\\\",r++):s==="-"&&r>0&&r<e.length-1?(t+="-",r++):s==="^"&&r===0?(t+="^",r++):(s==="]"&&r===0?t+="\\]":t+=s,r++)}return t+="]",t}var ms=new Map([["alnum","a-zA-Z0-9"],["alpha","a-zA-Z"],["ascii","\\x00-\\x7F"],["blank"," \\t"],["cntrl","\\x00-\\x1F\\x7F"],["digit","0-9"],["graph","!-~"],["lower","a-z"],["print"," -~"],["punct","!-/:-@\\[-`{-~"],["space"," \\t\\n\\r\\f\\v"],["upper","A-Z"],["word","a-zA-Z0-9_"],["xdigit","0-9A-Fa-f"]]);function gs(e){return ms.get(e)??""}function se(e,t,r,s){if(r==="prefix")return O(`^${t}`,"s").replace(e,"");let n=O(`${t}$`,"s");if(s)return n.replace(e,"");for(let a=e.length;a>=0;a--){let i=e.slice(a);if(n.test(i))return e.slice(0,a)}return e}function de(e,t){let r=Array.from(e.state.env.keys()),s=new Set,n=e.state.associativeArrays??new Set,a=new Set;for(let l of r){let o=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)_\d+$/);o&&a.add(o[1]);let u=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)__length$/);u&&a.add(u[1])}let i=l=>{for(let o of n){let u=`${o}_`;if(l.startsWith(u)&&l!==o)return!0}return!1};for(let l of r)if(l.startsWith(t))if(l.includes("__")){let o=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)__length$/);o?.[1].startsWith(t)&&s.add(o[1])}else if(/_\d+$/.test(l)){let o=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)_\d+$/);o?.[1].startsWith(t)&&s.add(o[1])}else i(l)||s.add(l);return[...s].sort()}function ys(e,t){let r=(a,i=2)=>String(a).padStart(i,"0");if(e===""){let a=r(t.getHours()),i=r(t.getMinutes()),l=r(t.getSeconds());return`${a}:${i}:${l}`}let s="",n=0;for(;n<e.length;)if(e[n]==="%"){if(n+1>=e.length){s+="%",n++;continue}let a=e[n+1];switch(a){case"H":s+=r(t.getHours());break;case"M":s+=r(t.getMinutes());break;case"S":s+=r(t.getSeconds());break;case"d":s+=r(t.getDate());break;case"m":s+=r(t.getMonth()+1);break;case"Y":s+=t.getFullYear();break;case"y":s+=r(t.getFullYear()%100);break;case"I":{let i=t.getHours()%12;i===0&&(i=12),s+=r(i);break}case"p":s+=t.getHours()<12?"AM":"PM";break;case"P":s+=t.getHours()<12?"am":"pm";break;case"%":s+="%";break;case"a":{s+=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"][t.getDay()];break}case"b":{s+=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][t.getMonth()];break}default:s+=`%${a}`}n+=2}else s+=e[n],n++;return s}function be(e,t){let r="",s=0,n=e.state.env.get("USER")||e.state.env.get("LOGNAME")||"user",a=e.state.env.get("HOSTNAME")||"localhost",i=a.split(".")[0],l=e.state.env.get("PWD")||"/",o=e.state.env.get("HOME")||"/",u=l.startsWith(o)?`~${l.slice(o.length)}`:l,c=l.split("/").pop()||l,f=new Date,p=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],d=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],g=e.state.env.get("__COMMAND_NUMBER")||"1";for(;s<t.length;){let m=t[s];if(m==="\\"){if(s+1>=t.length){r+="\\",s++;continue}let E=t[s+1];if(E>="0"&&E<="7"){let A="",S=s+1;for(;S<t.length&&S<s+4&&t[S]>="0"&&t[S]<="7";)A+=t[S],S++;let y=Number.parseInt(A,8)%256;r+=String.fromCharCode(y),s=S;continue}switch(E){case"\\":r+="\\",s+=2;break;case"a":r+="\x07",s+=2;break;case"e":r+="\x1B",s+=2;break;case"n":r+=`
|
|
63
|
-
`,s+=2;break;case"r":r+="\r",s+=2;break;case"$":r+="$",s+=2;break;case"[":case"]":s+=2;break;case"u":r+=n,s+=2;break;case"h":r+=i,s+=2;break;case"H":r+=a,s+=2;break;case"w":r+=u,s+=2;break;case"W":r+=c,s+=2;break;case"d":{let A=String(f.getDate()).padStart(2," ");r+=`${p[f.getDay()]} ${d[f.getMonth()]} ${A}`,s+=2;break}case"t":{let A=String(f.getHours()).padStart(2,"0"),S=String(f.getMinutes()).padStart(2,"0"),y=String(f.getSeconds()).padStart(2,"0");r+=`${A}:${S}:${y}`,s+=2;break}case"T":{let A=f.getHours()%12;A===0&&(A=12);let S=String(A).padStart(2,"0"),y=String(f.getMinutes()).padStart(2,"0"),b=String(f.getSeconds()).padStart(2,"0");r+=`${S}:${y}:${b}`,s+=2;break}case"@":{let A=f.getHours()%12;A===0&&(A=12);let S=String(A).padStart(2,"0"),y=String(f.getMinutes()).padStart(2,"0"),b=f.getHours()<12?"AM":"PM";r+=`${S}:${y} ${b}`,s+=2;break}case"A":{let A=String(f.getHours()).padStart(2,"0"),S=String(f.getMinutes()).padStart(2,"0");r+=`${A}:${S}`,s+=2;break}case"D":if(s+2<t.length&&t[s+2]==="{"){let A=t.indexOf("}",s+3);if(A!==-1){let S=t.slice(s+3,A);r+=
|
|
64
|
-
`:r+="\\n";break;case"\r":r+="\\r";break;case" ":r+="\\t";break;default:{let n=s.charCodeAt(0);n<32||n===127?r+=`\\${n.toString(8).padStart(3,"0")}`:r+=s}}return`${r}'`}return`'${e}'`}function
|
|
65
|
-
`;throw new j(1,"",s)}return null}function
|
|
66
|
-
`)}return s.effectiveValue}async function
|
|
67
|
-
`);let c=P(e,u),f=0;if(n<0){if(c.length>0){let p=c[c.length-1][0],g=(typeof p=="number"?p:0)+1+n;if(g<0||(f=c.findIndex(([m])=>typeof m=="number"&&m>=g),f<0))return""}}else if(f=c.findIndex(([p])=>typeof p=="number"&&p>=n),f<0)return"";if(a!==void 0){if(a<0)throw new C(`${i[1]}[@]: substring expression < 0`);return c.slice(f,f+a).map(([,p])=>p).join(" ")}return c.slice(f).map(([,p])=>p).join(" ")}let l=[...r],o=n;if(o<0&&(o=Math.max(0,l.length+o)),a!==void 0){if(a<0){let u=l.length+a;return l.slice(o,Math.max(o,u)).join("")}return l.slice(o,o+a).join("")}return l.slice(o).join("")}async function
|
|
68
|
-
`;case"r":return"\r";case"t":return" ";case"v":return"\v";case"'":return"'";case'"':return'"';case"?":return"?";default:return o}});case"K":case"k":return s?"":le(r);case"u":return r.charAt(0).toUpperCase()+r.slice(1);case"U":return r.toUpperCase();case"L":return r.toLowerCase();default:return r}}async function $n(e,t,r,s,n,a,i=!1){if(L(e,t))return Ae(e,t)||"";let l=/^[a-zA-Z_][a-zA-Z0-9_]*\[([@*])\]$/.test(t);if(s){if(n.innerOp?.type==="UseAlternative")return"";throw new re(`\${!${t}}`)}let o=r;if(l&&(o===""||o.includes(" ")))throw new re(`\${!${t}}`);let u=o.match(/^[a-zA-Z_][a-zA-Z0-9_]*\[(.+)\]$/);if(u&&u[1].includes("~"))throw new re(`\${!${t}}`);if(n.innerOp){let c={type:"ParameterExpansion",parameter:o,operation:n.innerOp};return a(e,c,i)}return await v(e,o)}function _n(e,t){let s=P(e,t.array).map(([n])=>String(n));return t.star?s.join(N(e.state.env)):s.join(" ")}function Cn(e,t){let r=de(e,t.prefix);return t.star?r.join(N(e.state.env)):r.join(" ")}function On(e,t,r,s){let n=Number.parseInt(e.state.env.get("#")||"0",10),a=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(t==="*")return{isEmpty:n===0,effectiveValue:r};if(t==="@")return{isEmpty:n===0||n===1&&e.state.env.get("1")==="",effectiveValue:r};if(a){let[,i,l]=a,o=P(e,i);if(o.length===0)return{isEmpty:!0,effectiveValue:""};if(l==="*"){let u=N(e.state.env),c=o.map(([,f])=>f).join(u);return{isEmpty:s?c==="":!1,effectiveValue:c}}return{isEmpty:o.length===1&&o.every(([,u])=>u===""),effectiveValue:o.map(([,u])=>u).join(" ")}}return{isEmpty:r==="",effectiveValue:r}}function Ln(e){let t=0;for(;t<e.length;){let r=e[t];if(r==="\\"&&t+1<e.length){t+=2;continue}if(r==="'"){let s=e.indexOf("'",t+1);if(s!==-1){t=s+1;continue}}if(r==="$"&&t+1<e.length&&e[t+1]==="("||r==="`")return!0;t++}return!1}function Wn(e,t){let r=1,s=t,n=!1,a=!1;for(;s<e.length&&r>0;){let i=e[s];if(i==="\\"&&!n&&s+1<e.length){s+=2;continue}if(i==="'"&&!a){n=!n,s++;continue}if(i==='"'&&!n){a=!a,s++;continue}if(!n&&!a){if(i==="(")r++;else if(i===")"&&(r--,r===0))return s}s++}return-1}async function We(e,t){let r=new M,s;try{s=r.parse(t)}catch{return""}let n=e.state.bashPid;e.state.bashPid=e.state.nextVirtualPid++;let a=new Map(e.state.env),i=e.state.cwd,l=e.state.suppressVerbose;e.state.suppressVerbose=!0;try{let o=await e.executeScript(s),u=o.exitCode;return e.state.env=a,e.state.cwd=i,e.state.suppressVerbose=l,e.state.lastExitCode=u,e.state.env.set("?",String(u)),o.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+o.stderr),e.state.bashPid=n,o.stdout.replace(/\n+$/,"")}catch(o){if(e.state.env=a,e.state.cwd=i,e.state.bashPid=n,e.state.suppressVerbose=l,o instanceof B)throw o;return o instanceof j?(e.state.lastExitCode=o.exitCode,e.state.env.set("?",String(o.exitCode)),o.stdout?.replace(/\n+$/,"")??""):""}}function wt(e,t){let r="",s=0;for(;s<t.length;){let n=t[s];if(n==="'"){let a=t.indexOf("'",s+1);if(a!==-1){let i=t.slice(s+1,a);r+=K(i),s=a+1;continue}}if(n==='"'){let a=-1,i=s+1;for(;i<t.length;){if(t[i]==="\\"){i+=2;continue}if(t[i]==='"'){a=i;break}i++}if(a!==-1){let l=t.slice(s+1,a),o=Es(e,l);r+=K(o),s=a+1;continue}}if(n==="$"&&s+1<t.length){let a=t[s+1];if(a==="{"){let i=t.indexOf("}",s+2);if(i!==-1){let l=t.slice(s+2,i);r+=e.state.env.get(l)??"",s=i+1;continue}}else if(/[a-zA-Z_]/.test(a)){let i=s+1;for(;i<t.length&&/[a-zA-Z0-9_]/.test(t[i]);)i++;let l=t.slice(s+1,i);r+=e.state.env.get(l)??"",s=i;continue}}if(n==="\\"&&s+1<t.length){r+=n+t[s+1],s+=2;continue}r+=n,s++}return r}function Es(e,t){let r="",s=0;for(;s<t.length;){let n=t[s];if(n==="\\"&&s+1<t.length){let a=t[s+1];if(a==="$"||a==="`"||a==="\\"||a==='"'){r+=a,s+=2;continue}r+=n,s++;continue}if(n==="$"&&s+1<t.length){let a=t[s+1];if(a==="{"){let i=t.indexOf("}",s+2);if(i!==-1){let l=t.slice(s+2,i);r+=e.state.env.get(l)??"",s=i+1;continue}}else if(/[a-zA-Z_]/.test(a)){let i=s+1;for(;i<t.length&&/[a-zA-Z0-9_]/.test(t[i]);)i++;let l=t.slice(s+1,i);r+=e.state.env.get(l)??"",s=i;continue}}r+=n,s++}return r}async function Tn(e,t){let r="",s=0;for(;s<t.length;){let n=t[s];if(n==="'"){let a=t.indexOf("'",s+1);if(a!==-1){let i=t.slice(s+1,a);r+=K(i),s=a+1;continue}}if(n==='"'){let a=-1,i=s+1;for(;i<t.length;){if(t[i]==="\\"){i+=2;continue}if(t[i]==='"'){a=i;break}i++}if(a!==-1){let l=t.slice(s+1,a),o=await As(e,l);r+=K(o),s=a+1;continue}}if(n==="$"&&s+1<t.length&&t[s+1]==="("){let a=Wn(t,s+2);if(a!==-1){let i=t.slice(s+2,a),l=await We(e,i);r+=l,s=a+1;continue}}if(n==="`"){let a=t.indexOf("`",s+1);if(a!==-1){let i=t.slice(s+1,a),l=await We(e,i);r+=l,s=a+1;continue}}if(n==="$"&&s+1<t.length){let a=t[s+1];if(a==="{"){let i=t.indexOf("}",s+2);if(i!==-1){let l=t.slice(s+2,i);r+=e.state.env.get(l)??"",s=i+1;continue}}else if(/[a-zA-Z_]/.test(a)){let i=s+1;for(;i<t.length&&/[a-zA-Z0-9_]/.test(t[i]);)i++;let l=t.slice(s+1,i);r+=e.state.env.get(l)??"",s=i;continue}}if(n==="\\"&&s+1<t.length){r+=n+t[s+1],s+=2;continue}r+=n,s++}return r}async function As(e,t){let r="",s=0;for(;s<t.length;){let n=t[s];if(n==="\\"&&s+1<t.length){let a=t[s+1];if(a==="$"||a==="`"||a==="\\"||a==='"'){r+=a,s+=2;continue}r+=n,s++;continue}if(n==="$"&&s+1<t.length&&t[s+1]==="("){let a=Wn(t,s+2);if(a!==-1){let i=t.slice(s+2,a),l=await We(e,i);r+=l,s=a+1;continue}}if(n==="`"){let a=t.indexOf("`",s+1);if(a!==-1){let i=t.slice(s+1,a),l=await We(e,i);r+=l,s=a+1;continue}}if(n==="$"&&s+1<t.length){let a=t[s+1];if(a==="{"){let i=t.indexOf("}",s+2);if(i!==-1){let l=t.slice(s+2,i);r+=e.state.env.get(l)??"",s=i+1;continue}}else if(/[a-zA-Z_]/.test(a)){let i=s+1;for(;i<t.length&&/[a-zA-Z0-9_]/.test(t[i]);)i++;let l=t.slice(s+1,i);r+=e.state.env.get(l)??"",s=i;continue}}r+=n,s++}return r}function Mn(e,t){if(!t.startsWith("~"))return t;let r=e.state.env.get("HOME")!==void 0?e.state.env.get("HOME"):"/home/user";if(t==="~"||t.startsWith("~/"))return r+t.slice(1);let s=1;for(;s<t.length&&/[a-zA-Z0-9_-]/.test(t[s]);)s++;let n=t.slice(1,s),a=t.slice(s);return a!==""&&!a.startsWith("/")?t:n==="root"?`/root${a}`:t}async function Ss(e,t,r,s){let n="";for(let a of t.parts)if(a.type==="Glob")n+=k(a.pattern,!0,e.state.shoptOptions.extglob);else if(a.type==="Literal")n+=k(a.value,!0,e.state.shoptOptions.extglob);else if(a.type==="SingleQuoted"||a.type==="Escaped")n+=I(a.value);else if(a.type==="DoubleQuoted"){let i=await r(e,a.parts);n+=I(i)}else if(a.type==="ParameterExpansion"){let i=await s(e,a);n+=k(i,!0,e.state.shoptOptions.extglob)}else{let i=await s(e,a);n+=I(i)}return n}async function Vn(e,t,r,s){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0];if(n.parts.length!==1||n.parts[0].type!=="ParameterExpansion"||n.parts[0].operation?.type!=="PatternReplacement")return null;let a=n.parts[0],i=a.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!i)return null;let l=i[1],o=i[2]==="*",u=a.operation,c=P(e,l),f=c.map(([,E])=>E);if(c.length===0){let E=e.state.env.get(l);E!==void 0&&f.push(E)}if(f.length===0)return{values:[],quoted:!0};let p="";u.pattern&&(p=await Ss(e,u.pattern,r,s));let d=u.replacement?await r(e,u.replacement.parts):"",g=p;u.anchor==="start"?g=`^${p}`:u.anchor==="end"&&(g=`${p}$`);let m=[];try{let E=O(g,u.all?"g":"");for(let A of f)m.push(E.replace(A,d))}catch{m.push(...f)}if(o){let E=N(e.state.env);return{values:[m.join(E)],quoted:!0}}return{values:m,quoted:!0}}async function qn(e,t,r,s){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0];if(n.parts.length!==1||n.parts[0].type!=="ParameterExpansion"||n.parts[0].operation?.type!=="PatternRemoval")return null;let a=n.parts[0],i=a.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!i)return null;let l=i[1],o=i[2]==="*",u=a.operation,c=P(e,l),f=c.map(([,m])=>m);if(c.length===0){let m=e.state.env.get(l);m!==void 0&&f.push(m)}if(f.length===0)return{values:[],quoted:!0};let p="",d=e.state.shoptOptions.extglob;if(u.pattern)for(let m of u.pattern.parts)if(m.type==="Glob")p+=k(m.pattern,u.greedy,d);else if(m.type==="Literal")p+=k(m.value,u.greedy,d);else if(m.type==="SingleQuoted"||m.type==="Escaped")p+=I(m.value);else if(m.type==="DoubleQuoted"){let E=await r(e,m.parts);p+=I(E)}else if(m.type==="ParameterExpansion"){let E=await s(e,m);p+=k(E,u.greedy,d)}else{let E=await s(e,m);p+=I(E)}let g=[];for(let m of f)g.push(se(m,p,u.side,u.greedy));if(o){let m=N(e.state.env);return{values:[g.join(m)],quoted:!0}}return{values:g,quoted:!0}}async function Bn(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let r=t[0];if(r.parts.length!==1||r.parts[0].type!=="ParameterExpansion"||r.parts[0].operation?.type!=="DefaultValue"&&r.parts[0].operation?.type!=="UseAlternative"&&r.parts[0].operation?.type!=="AssignDefault")return null;let s=r.parts[0],n=s.operation,a=s.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/),i,l=!1;if(a){let o=a[1];l=a[2]==="*";let u=P(e,o),c=u.length>0||e.state.env.has(o),f=u.length===0||u.length===1&&u.every(([,d])=>d===""),p=n.checkEmpty??!1;if(n.type==="UseAlternative"?i=c&&!(p&&f):i=!c||p&&f,!i){if(u.length>0){let g=u.map(([,m])=>m);if(l){let m=N(e.state.env);return{values:[g.join(m)],quoted:!0}}return{values:g,quoted:!0}}let d=e.state.env.get(o);return d!==void 0?{values:[d],quoted:!0}:{values:[],quoted:!0}}}else{let o=s.parameter,u=await te(e,o),c=await v(e,o),f=c==="",p=n.checkEmpty??!1;if(n.type==="UseAlternative"?i=u&&!(p&&f):i=!u||p&&f,!i)return{values:[c],quoted:!0}}if(i&&n.word){let o=n.word.parts,u=null,c=!1;for(let f of o)if(f.type==="ParameterExpansion"&&!f.operation){let p=f.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(p){u=p[1],c=p[2]==="*";break}}if(u){let f=P(e,u);if(f.length>0){let d=f.map(([,g])=>g);if(c||l){let g=N(e.state.env);return{values:[d.join(g)],quoted:!0}}return{values:d,quoted:!0}}let p=e.state.env.get(u);return p!==void 0?{values:[p],quoted:!0}:{values:[],quoted:!0}}}return null}async function Fn(e,t,r,s,n){if(!r||t.length!==1||t[0].type!=="DoubleQuoted")return null;let a=t[0],i=-1,l="",o=!1,u=null;for(let m=0;m<a.parts.length;m++){let E=a.parts[m];if(E.type==="ParameterExpansion"&&(E.operation?.type==="PatternRemoval"||E.operation?.type==="PatternReplacement")){let A=E.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(A){i=m,l=A[1],o=A[2]==="*",u=E.operation;break}}}if(i===-1||i===0&&i===a.parts.length-1)return null;let c="";for(let m=0;m<i;m++)c+=await s(e,a.parts[m]);let f="";for(let m=i+1;m<a.parts.length;m++)f+=await s(e,a.parts[m]);let p=P(e,l),d=p.map(([,m])=>m);if(p.length===0){let m=e.state.env.get(l);if(m!==void 0)d=[m];else{if(o)return{values:[c+f],quoted:!0};let E=c+f;return{values:E?[E]:[],quoted:!0}}}if(u?.type==="PatternRemoval"){let m=u,E="",A=e.state.shoptOptions.extglob;if(m.pattern)for(let S of m.pattern.parts)if(S.type==="Glob")E+=k(S.pattern,m.greedy,A);else if(S.type==="Literal")E+=k(S.value,m.greedy,A);else if(S.type==="SingleQuoted"||S.type==="Escaped")E+=I(S.value);else if(S.type==="DoubleQuoted"){let y=await n(e,S.parts);E+=I(y)}else if(S.type==="ParameterExpansion"){let y=await s(e,S);E+=k(y,m.greedy,A)}else{let y=await s(e,S);E+=I(y)}d=d.map(S=>se(S,E,m.side,m.greedy))}else if(u?.type==="PatternReplacement"){let m=u,E="";if(m.pattern)for(let y of m.pattern.parts)if(y.type==="Glob")E+=k(y.pattern,!0,e.state.shoptOptions.extglob);else if(y.type==="Literal")E+=k(y.value,!0,e.state.shoptOptions.extglob);else if(y.type==="SingleQuoted"||y.type==="Escaped")E+=I(y.value);else if(y.type==="DoubleQuoted"){let b=await n(e,y.parts);E+=I(b)}else if(y.type==="ParameterExpansion"){let b=await s(e,y);E+=k(b,!0,e.state.shoptOptions.extglob)}else{let b=await s(e,y);E+=I(b)}let A=m.replacement?await n(e,m.replacement.parts):"",S=E;m.anchor==="start"?S=`^${E}`:m.anchor==="end"&&(S=`${E}$`);try{let y=O(S,m.all?"g":"");d=d.map(b=>y.replace(b,A))}catch{}}if(o){let m=N(e.state.env);return{values:[c+d.join(m)+f],quoted:!0}}return d.length===1?{values:[c+d[0]+f],quoted:!0}:{values:[c+d[0],...d.slice(1,-1),d[d.length-1]+f],quoted:!0}}async function Qn(e,t,r,s){if(!r||t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0],a=-1,i="",l=!1;for(let d=0;d<n.parts.length;d++){let g=n.parts[d];if(g.type==="ParameterExpansion"&&!g.operation){let m=g.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(m){a=d,i=m[1],l=m[2]==="*";break}}}if(a===-1)return null;let o="";for(let d=0;d<a;d++)o+=await s(e,n.parts[d]);let u="";for(let d=a+1;d<n.parts.length;d++)u+=await s(e,n.parts[d]);let c=P(e,i),f=c.map(([,d])=>d);if(c.length===0){let d=e.state.env.get(i);if(d!==void 0)return{values:[o+d+u],quoted:!0};if(l)return{values:[o+u],quoted:!0};let g=o+u;return{values:g?[g]:[],quoted:!0}}if(l){let d=N(e.state.env);return{values:[o+f.join(d)+u],quoted:!0}}return f.length===1?{values:[o+f[0]+u],quoted:!0}:{values:[o+f[0],...f.slice(1,-1),f[f.length-1]+u],quoted:!0}}async function zn(e,t,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0];if(s.parts.length!==1||s.parts[0].type!=="ParameterExpansion"||s.parts[0].operation?.type!=="Substring")return null;let n=s.parts[0],a=n.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!a)return null;let i=a[1],l=a[2]==="*",o=n.operation;if(e.state.associativeArrays?.has(i))throw new j(1,"",`bash: \${${i}[@]: 0: 3}: bad substitution
|
|
69
|
-
`);let u=o.offset?await r(e,o.offset.expression):0,c=o.length?await r(e,o.length.expression):void 0,f=P(e,i),p=0;if(u<0){if(f.length>0){let g=f[f.length-1][0],E=(typeof g=="number"?g:0)+1+u;if(E<0)return{values:[],quoted:!0};p=f.findIndex(([A])=>typeof A=="number"&&A>=E),p<0&&(p=f.length)}}else p=f.findIndex(([g])=>typeof g=="number"&&g>=u),p<0&&(p=f.length);let d;if(c!==void 0){if(c<0)throw new C(`${i}[@]: substring expression < 0`);d=f.slice(p,p+c).map(([,g])=>g)}else d=f.slice(p).map(([,g])=>g);if(d.length===0)return{values:[],quoted:!0};if(l){let g=N(e.state.env);return{values:[d.join(g)],quoted:!0}}return{values:d,quoted:!0}}function Zn(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let r=t[0];if(r.parts.length!==1||r.parts[0].type!=="ParameterExpansion"||r.parts[0].operation?.type!=="Transform")return null;let s=r.parts[0],n=s.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!n)return null;let a=n[1],i=n[2]==="*",l=s.operation,o=P(e,a);if(o.length===0){let f=e.state.env.get(a);if(f!==void 0){let p;switch(l.operator){case"a":p="";break;case"P":p=be(e,f);break;case"Q":p=le(f);break;default:p=f}return{values:[p],quoted:!0}}return i?{values:[""],quoted:!0}:{values:[],quoted:!0}}let u=ce(e,a),c;switch(l.operator){case"a":c=o.map(()=>u);break;case"P":c=o.map(([,f])=>be(e,f));break;case"Q":c=o.map(([,f])=>le(f));break;case"u":c=o.map(([,f])=>f.charAt(0).toUpperCase()+f.slice(1));break;case"U":c=o.map(([,f])=>f.toUpperCase());break;case"L":c=o.map(([,f])=>f.toLowerCase());break;default:c=o.map(([,f])=>f)}if(i){let f=N(e.state.env);return{values:[c.join(f)],quoted:!0}}return{values:c,quoted:!0}}function Gn(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let r=t[0];if(r.parts.length!==1||r.parts[0].type!=="ParameterExpansion")return null;let s=r.parts[0];if(s.operation)return null;let n=s.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(@)\]$/);if(!n)return null;let a=n[1];if(L(e,a)){let o=Ae(e,a);if(o?.endsWith("[@]")||o?.endsWith("[*]"))return{values:[],quoted:!0}}let i=P(e,a);if(i.length>0)return{values:i.map(([,o])=>o),quoted:!0};let l=e.state.env.get(a);return l!==void 0?{values:[l],quoted:!0}:{values:[],quoted:!0}}function Un(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let r=t[0];if(r.parts.length!==1||r.parts[0].type!=="ParameterExpansion"||r.parts[0].operation)return null;let n=r.parts[0].parameter;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n)||!L(e,n))return null;let a=Ae(e,n);if(!a)return null;let i=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(@)\]$/);if(!i)return null;let l=i[1],o=P(e,l);if(o.length>0)return{values:o.map(([,c])=>c),quoted:!0};let u=e.state.env.get(l);return u!==void 0?{values:[u],quoted:!0}:{values:[],quoted:!0}}async function Hn(e,t,r,s,n){if(!r||t.length!==1||t[0].type!=="DoubleQuoted")return null;let a=t[0];if(a.parts.length!==1||a.parts[0].type!=="ParameterExpansion"||a.parts[0].operation?.type!=="Indirection")return null;let i=a.parts[0],l=i.operation,o=await v(e,i.parameter),u=o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!u){if(!l.innerOp&&(o==="@"||o==="*")){let g=Number.parseInt(e.state.env.get("#")||"0",10),m=[];for(let E=1;E<=g;E++)m.push(e.state.env.get(String(E))||"");return o==="*"?{values:[m.join(N(e.state.env))],quoted:!0}:{values:m,quoted:!0}}return null}let c=u[1],f=u[2]==="*",p=P(e,c);if(l.innerOp){if(l.innerOp.type==="Substring")return bs(e,p,c,f,l.innerOp);if(l.innerOp.type==="DefaultValue"||l.innerOp.type==="UseAlternative"||l.innerOp.type==="AssignDefault"||l.innerOp.type==="ErrorIfUnset")return ws(e,p,c,f,l.innerOp,n);if(l.innerOp.type==="Transform"&&l.innerOp.operator==="a"){let m=ce(e,c),E=p.map(()=>m);return f?{values:[E.join(N(e.state.env))],quoted:!0}:{values:E,quoted:!0}}let g=[];for(let[,m]of p){let E={type:"ParameterExpansion",parameter:"_indirect_elem_",operation:l.innerOp},A=e.state.env.get("_indirect_elem_");e.state.env.set("_indirect_elem_",m);try{let S=await s(e,E,!0);g.push(S)}finally{A!==void 0?e.state.env.set("_indirect_elem_",A):e.state.env.delete("_indirect_elem_")}}return f?{values:[g.join(N(e.state.env))],quoted:!0}:{values:g,quoted:!0}}if(p.length>0){let g=p.map(([,m])=>m);return f?{values:[g.join(N(e.state.env))],quoted:!0}:{values:g,quoted:!0}}let d=e.state.env.get(c);return d!==void 0?{values:[d],quoted:!0}:{values:[],quoted:!0}}async function bs(e,t,r,s,n){let a=n.offset?await R(e,n.offset.expression):0,i=n.length?await R(e,n.length.expression):void 0,l=0;if(a<0){if(t.length>0){let c=t[t.length-1][0],p=(typeof c=="number"?c:0)+1+a;if(p<0)return{values:[],quoted:!0};if(l=t.findIndex(([d])=>typeof d=="number"&&d>=p),l<0)return{values:[],quoted:!0}}}else if(l=t.findIndex(([c])=>typeof c=="number"&&c>=a),l<0)return{values:[],quoted:!0};let o;if(i!==void 0){if(i<0)throw new C(`${r}[@]: substring expression < 0`);o=t.slice(l,l+i)}else o=t.slice(l);let u=o.map(([,c])=>c);return s?{values:[u.join(N(e.state.env))],quoted:!0}:{values:u,quoted:!0}}async function ws(e,t,r,s,n,a){let i=n.checkEmpty??!1,l=t.map(([,c])=>c),o=t.length===0,u=t.length===0;if(n.type==="UseAlternative")return!u&&!(i&&o)&&n.word?{values:[await a(e,n.word.parts,!0)],quoted:!0}:{values:[],quoted:!0};if(n.type==="DefaultValue")return(u||i&&o)&&n.word?{values:[await a(e,n.word.parts,!0)],quoted:!0}:s?{values:[l.join(N(e.state.env))],quoted:!0}:{values:l,quoted:!0};if(n.type==="AssignDefault"){if((u||i&&o)&&n.word){let f=await a(e,n.word.parts,!0);return e.state.env.set(`${r}_0`,f),e.state.env.set(`${r}__length`,"1"),{values:[f],quoted:!0}}return s?{values:[l.join(N(e.state.env))],quoted:!0}:{values:l,quoted:!0}}return s?{values:[l.join(N(e.state.env))],quoted:!0}:{values:l,quoted:!0}}async function jn(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="UseAlternative"&&t[0].operation?.type!=="DefaultValue")return null;let r=t[0],s=r.operation,n=s?.word;if(!n||n.parts.length!==1||n.parts[0].type!=="DoubleQuoted")return null;let a=n.parts[0];if(a.parts.length!==1||a.parts[0].type!=="ParameterExpansion"||a.parts[0].operation?.type!=="Indirection")return null;let i=a.parts[0],o=(await v(e,i.parameter)).match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!o)return null;let u=await te(e,r.parameter),c=await v(e,r.parameter)==="",f=s.checkEmpty??!1,p;if(s.type==="UseAlternative"?p=u&&!(f&&c):p=!u||f&&c,p){let d=o[1],g=o[2]==="*",m=P(e,d);if(m.length>0){let A=m.map(([,S])=>S);return g?{values:[A.join(N(e.state.env))],quoted:!0}:{values:A,quoted:!0}}let E=e.state.env.get(d);return E!==void 0?{values:[E],quoted:!0}:{values:[],quoted:!0}}return{values:[],quoted:!1}}async function Kn(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="Indirection")return null;let r=t[0],n=r.operation.innerOp;if(!n||n.type!=="UseAlternative"&&n.type!=="DefaultValue")return null;let a=n.word;if(!a||a.parts.length!==1||a.parts[0].type!=="DoubleQuoted")return null;let i=a.parts[0];if(i.parts.length!==1||i.parts[0].type!=="ParameterExpansion"||i.parts[0].operation?.type!=="Indirection")return null;let l=i.parts[0],u=(await v(e,l.parameter)).match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!u)return null;let c=await v(e,r.parameter),f=await te(e,r.parameter),p=c==="",d=n.checkEmpty??!1,g;if(n.type==="UseAlternative"?g=f&&!(d&&p):g=!f||d&&p,g){let m=u[1],E=u[2]==="*",A=P(e,m);if(A.length>0){let y=A.map(([,b])=>b);return E?{values:[y.join(N(e.state.env))],quoted:!0}:{values:y,quoted:!0}}let S=e.state.env.get(m);return S!==void 0?{values:[S],quoted:!0}:{values:[],quoted:!0}}return{values:[],quoted:!1}}function Xn(e){let t=Number.parseInt(e.state.env.get("#")||"0",10),r=[];for(let s=1;s<=t;s++)r.push(e.state.env.get(String(s))||"");return r}async function Jn(e,t,r,s){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0],a=-1,i=!1;for(let S=0;S<n.parts.length;S++){let y=n.parts[S];if(y.type==="ParameterExpansion"&&(y.parameter==="@"||y.parameter==="*")&&y.operation?.type==="Substring"){a=S,i=y.parameter==="*";break}}if(a===-1)return null;let o=n.parts[a].operation,u=o.offset?await r(e,o.offset.expression):0,c=o.length?await r(e,o.length.expression):void 0,f=Number.parseInt(e.state.env.get("#")||"0",10),p=[];for(let S=1;S<=f;S++)p.push(e.state.env.get(String(S))||"");let d=e.state.env.get("0")||"bash",g;if(u<=0){let S=[d,...p],y=S.length+u;if(y<0)g=[];else{let b=u<0?y:0;if(c!==void 0){let D=c<0?S.length+c:b+c;g=S.slice(b,Math.max(b,D))}else g=S.slice(b)}}else{let S=u-1;if(S>=p.length)g=[];else if(c!==void 0){let y=c<0?p.length+c:S+c;g=p.slice(S,Math.max(S,y))}else g=p.slice(S)}let m="";for(let S=0;S<a;S++)m+=await s(e,n.parts[S]);let E="";for(let S=a+1;S<n.parts.length;S++)E+=await s(e,n.parts[S]);if(g.length===0){let S=m+E;return{values:S?[S]:[],quoted:!0}}if(i){let S=N(e.state.env);return{values:[m+g.join(S)+E],quoted:!0}}return g.length===1?{values:[m+g[0]+E],quoted:!0}:{values:[m+g[0],...g.slice(1,-1),g[g.length-1]+E],quoted:!0}}async function Yn(e,t,r,s){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0],a=-1,i=!1;for(let A=0;A<n.parts.length;A++){let S=n.parts[A];if(S.type==="ParameterExpansion"&&(S.parameter==="@"||S.parameter==="*")&&S.operation?.type==="PatternReplacement"){a=A,i=S.parameter==="*";break}}if(a===-1)return null;let o=n.parts[a].operation,u=Xn(e),c="";for(let A=0;A<a;A++)c+=await r(e,n.parts[A]);let f="";for(let A=a+1;A<n.parts.length;A++)f+=await r(e,n.parts[A]);if(u.length===0){let A=c+f;return{values:A?[A]:[],quoted:!0}}let p="";if(o.pattern)for(let A of o.pattern.parts)if(A.type==="Glob")p+=k(A.pattern,!0,e.state.shoptOptions.extglob);else if(A.type==="Literal")p+=k(A.value,!0,e.state.shoptOptions.extglob);else if(A.type==="SingleQuoted"||A.type==="Escaped")p+=I(A.value);else if(A.type==="DoubleQuoted"){let S=await s(e,A.parts);p+=I(S)}else if(A.type==="ParameterExpansion"){let S=await r(e,A);p+=k(S,!0,e.state.shoptOptions.extglob)}else{let S=await r(e,A);p+=I(S)}let d=o.replacement?await s(e,o.replacement.parts):"",g=p;o.anchor==="start"?g=`^${p}`:o.anchor==="end"&&(g=`${p}$`);let m=[];try{let A=O(g,o.all?"g":"");for(let S of u)m.push(A.replace(S,d))}catch{m.push(...u)}if(i){let A=N(e.state.env);return{values:[c+m.join(A)+f],quoted:!0}}return m.length===1?{values:[c+m[0]+f],quoted:!0}:{values:[c+m[0],...m.slice(1,-1),m[m.length-1]+f],quoted:!0}}async function er(e,t,r,s){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0],a=-1,i=!1;for(let E=0;E<n.parts.length;E++){let A=n.parts[E];if(A.type==="ParameterExpansion"&&(A.parameter==="@"||A.parameter==="*")&&A.operation?.type==="PatternRemoval"){a=E,i=A.parameter==="*";break}}if(a===-1)return null;let o=n.parts[a].operation,u=Xn(e),c="";for(let E=0;E<a;E++)c+=await r(e,n.parts[E]);let f="";for(let E=a+1;E<n.parts.length;E++)f+=await r(e,n.parts[E]);if(u.length===0){let E=c+f;return{values:E?[E]:[],quoted:!0}}let p="",d=e.state.shoptOptions.extglob;if(o.pattern)for(let E of o.pattern.parts)if(E.type==="Glob")p+=k(E.pattern,o.greedy,d);else if(E.type==="Literal")p+=k(E.value,o.greedy,d);else if(E.type==="SingleQuoted"||E.type==="Escaped")p+=I(E.value);else if(E.type==="DoubleQuoted"){let A=await s(e,E.parts);p+=I(A)}else if(E.type==="ParameterExpansion"){let A=await r(e,E);p+=k(A,o.greedy,d)}else{let A=await r(e,E);p+=I(A)}let g=[];for(let E of u)g.push(se(E,p,o.side,o.greedy));if(i){let E=N(e.state.env);return{values:[c+g.join(E)+f],quoted:!0}}return g.length===1?{values:[c+g[0]+f],quoted:!0}:{values:[c+g[0],...g.slice(1,-1),g[g.length-1]+f],quoted:!0}}async function tr(e,t,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0],n=-1,a=!1;for(let p=0;p<s.parts.length;p++){let d=s.parts[p];if(d.type==="ParameterExpansion"&&(d.parameter==="@"||d.parameter==="*")){n=p,a=d.parameter==="*";break}}if(n===-1)return null;let i=s.parts[n];if(i.type==="ParameterExpansion"&&i.operation)return null;let l=Number.parseInt(e.state.env.get("#")||"0",10),o="";for(let p=0;p<n;p++)o+=await r(e,s.parts[p]);let u="";for(let p=n+1;p<s.parts.length;p++)u+=await r(e,s.parts[p]);if(l===0){if(a)return{values:[o+u],quoted:!0};let p=o+u;return{values:p?[p]:[],quoted:!0}}let c=[];for(let p=1;p<=l;p++)c.push(e.state.env.get(String(p))||"");if(a){let p=N(e.state.env);return{values:[o+c.join(p)+u],quoted:!0}}return c.length===1?{values:[o+c[0]+u],quoted:!0}:{values:[o+c[0],...c.slice(1,-1),c[c.length-1]+u],quoted:!0}}function Ns(e){return new oe(e.fs,e.state.cwd,e.state.env,{globstar:e.state.shoptOptions.globstar,nullglob:e.state.shoptOptions.nullglob,failglob:e.state.shoptOptions.failglob,dotglob:e.state.shoptOptions.dotglob,extglob:e.state.shoptOptions.extglob,globskipdots:e.state.shoptOptions.globskipdots,maxGlobOperations:e.limits.maxGlobOperations})}async function Te(e,t){if(e.state.options.noglob)return t;let r=Ns(e),s=[];for(let n of t)if(ne(n,e.state.shoptOptions.extglob)){let a=await r.expand(n);if(a.length>0)s.push(...a);else{if(r.hasFailglob())throw new Pe(n);r.hasNullglob()||s.push(n)}}else s.push(n);return s}async function nr(e,t,r,s){let n=-1,a="",i=!1;for(let S=0;S<t.length;S++){let y=t[S];if(y.type==="ParameterExpansion"&&y.operation?.type==="PatternReplacement"){let b=y.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(b){n=S,a=b[1],i=b[2]==="*";break}}}if(n===-1)return null;let o=t[n].operation,u=P(e,a),c=u.map(([,S])=>S);if(u.length===0){let S=e.state.env.get(a);S!==void 0&&(c=[S])}if(c.length===0)return{values:[],quoted:!1};let f="";if(o.pattern)for(let S of o.pattern.parts)if(S.type==="Glob")f+=k(S.pattern,!0,e.state.shoptOptions.extglob);else if(S.type==="Literal")f+=k(S.value,!0,e.state.shoptOptions.extglob);else if(S.type==="SingleQuoted"||S.type==="Escaped")f+=I(S.value);else if(S.type==="DoubleQuoted"){let y=await r(e,S.parts);f+=I(y)}else if(S.type==="ParameterExpansion"){let y=await s(e,S);f+=k(y,!0,e.state.shoptOptions.extglob)}else{let y=await s(e,S);f+=I(y)}let p=o.replacement?await r(e,o.replacement.parts):"",d=f;o.anchor==="start"?d=`^${f}`:o.anchor==="end"&&(d=`${f}$`);let g=[];try{let S=O(d,o.all?"g":"");for(let y of c)g.push(S.replace(y,p))}catch{g.push(...c)}let m=W(e.state.env),E=V(e.state.env);if(i){let S=N(e.state.env),y=g.join(S);return E?{values:y?[y]:[],quoted:!1}:{values:x(y,m),quoted:!1}}if(E)return{values:g,quoted:!1};let A=[];for(let S of g)S===""?A.push(""):A.push(...x(S,m));return{values:A,quoted:!1}}async function rr(e,t,r,s){let n=-1,a="",i=!1;for(let A=0;A<t.length;A++){let S=t[A];if(S.type==="ParameterExpansion"&&S.operation?.type==="PatternRemoval"){let y=S.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(y){n=A,a=y[1],i=y[2]==="*";break}}}if(n===-1)return null;let o=t[n].operation,u=P(e,a),c=u.map(([,A])=>A);if(u.length===0){let A=e.state.env.get(a);A!==void 0&&(c=[A])}if(c.length===0)return{values:[],quoted:!1};let f="",p=e.state.shoptOptions.extglob;if(o.pattern)for(let A of o.pattern.parts)if(A.type==="Glob")f+=k(A.pattern,o.greedy,p);else if(A.type==="Literal")f+=k(A.value,o.greedy,p);else if(A.type==="SingleQuoted"||A.type==="Escaped")f+=I(A.value);else if(A.type==="DoubleQuoted"){let S=await r(e,A.parts);f+=I(S)}else if(A.type==="ParameterExpansion"){let S=await s(e,A);f+=k(S,o.greedy,p)}else{let S=await s(e,A);f+=I(S)}let d=[];for(let A of c)d.push(se(A,f,o.side,o.greedy));let g=W(e.state.env),m=V(e.state.env);if(i){let A=N(e.state.env),S=d.join(A);return m?{values:S?[S]:[],quoted:!1}:{values:x(S,g),quoted:!1}}if(m)return{values:d,quoted:!1};let E=[];for(let A of d)A===""?E.push(""):E.push(...x(A,g));return{values:E,quoted:!1}}async function sr(e,t,r,s){let n=-1,a=!1;for(let E=0;E<t.length;E++){let A=t[E];if(A.type==="ParameterExpansion"&&(A.parameter==="@"||A.parameter==="*")&&A.operation?.type==="PatternRemoval"){n=E,a=A.parameter==="*";break}}if(n===-1)return null;let l=t[n].operation,o=Number.parseInt(e.state.env.get("#")||"0",10),u=[];for(let E=1;E<=o;E++)u.push(e.state.env.get(String(E))||"");if(u.length===0)return{values:[],quoted:!1};let c="",f=e.state.shoptOptions.extglob;if(l.pattern)for(let E of l.pattern.parts)if(E.type==="Glob")c+=k(E.pattern,l.greedy,f);else if(E.type==="Literal")c+=k(E.value,l.greedy,f);else if(E.type==="SingleQuoted"||E.type==="Escaped")c+=I(E.value);else if(E.type==="DoubleQuoted"){let A=await r(e,E.parts);c+=I(A)}else if(E.type==="ParameterExpansion"){let A=await s(e,E);c+=k(A,l.greedy,f)}else{let A=await s(e,E);c+=I(A)}let p=[];for(let E of u)p.push(se(E,c,l.side,l.greedy));let d=W(e.state.env),g=V(e.state.env);if(a){let E=N(e.state.env),A=p.join(E);return g?{values:A?[A]:[],quoted:!1}:{values:x(A,d),quoted:!1}}if(g)return{values:p,quoted:!1};let m=[];for(let E of p)E===""?m.push(""):m.push(...x(E,d));return{values:m,quoted:!1}}async function ir(e,t,r,s){let n=-1,a=!1;for(let y=0;y<t.length;y++){let b=t[y];if(b.type==="ParameterExpansion"&&(b.parameter==="@"||b.parameter==="*")&&b.operation?.type==="Substring"){n=y,a=b.parameter==="*";break}}if(n===-1)return null;let l=t[n].operation,o=l.offset?await r(e,l.offset.expression):0,u=l.length?await r(e,l.length.expression):void 0,c=Number.parseInt(e.state.env.get("#")||"0",10),f=[];for(let y=1;y<=c;y++)f.push(e.state.env.get(String(y))||"");let p=e.state.env.get("0")||"bash",d;if(o<=0){let y=[p,...f],b=y.length+o;if(b<0)d=[];else{let D=o<0?b:0;if(u!==void 0){let z=u<0?y.length+u:D+u;d=y.slice(D,Math.max(D,z))}else d=y.slice(D)}}else{let y=o-1;if(y>=f.length)d=[];else if(u!==void 0){let b=u<0?f.length+u:y+u;d=f.slice(y,Math.max(y,b))}else d=f.slice(y)}let g="";for(let y=0;y<n;y++)g+=await s(e,t[y]);let m="";for(let y=n+1;y<t.length;y++)m+=await s(e,t[y]);let E=W(e.state.env),A=V(e.state.env);if(d.length===0){let y=g+m;return y?A?{values:[y],quoted:!1}:{values:x(y,E),quoted:!1}:{values:[],quoted:!1}}let S;if(a){let y=N(e.state.env),b=g+d.join(y)+m;A?S=b?[b]:[]:S=x(b,E)}else if(A)d.length===1?S=[g+d[0]+m]:S=[g+d[0],...d.slice(1,-1),d[d.length-1]+m];else{S=[];for(let y=0;y<d.length;y++){let b=d[y];if(y===0&&(b=g+b),y===d.length-1&&(b=b+m),b==="")S.push("");else{let D=x(b,E);S.push(...D)}}}return{values:await Te(e,S),quoted:!1}}async function ar(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].parameter!=="@"&&t[0].parameter!=="*"||t[0].operation)return null;let r=t[0].parameter==="*",s=Number.parseInt(e.state.env.get("#")||"0",10);if(s===0)return{values:[],quoted:!1};let n=[];for(let u=1;u<=s;u++)n.push(e.state.env.get(String(u))||"");let a=W(e.state.env),i=V(e.state.env),l=Ce(e.state.env),o;if(r)if(i)o=n.filter(u=>u!=="");else{let u=N(e.state.env),c=n.join(u);o=x(c,a)}else if(i)o=n.filter(u=>u!=="");else if(l){o=[];for(let u of n){if(u==="")continue;let c=x(u,a);o.push(...c)}}else{o=[];for(let u of n)if(u==="")o.push("");else{let c=x(u,a);o.push(...c)}for(;o.length>0&&o[o.length-1]==="";)o.pop()}return{values:await Te(e,o),quoted:!1}}async function or(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation)return null;let r=t[0].parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!r)return null;let s=r[1],n=r[2]==="*",a=P(e,s),i;if(a.length===0){let f=e.state.env.get(s);if(f!==void 0)i=[f];else return{values:[],quoted:!1}}else i=a.map(([,f])=>f);let l=W(e.state.env),o=V(e.state.env),u=Ce(e.state.env),c;if(n)if(o)c=i.filter(f=>f!=="");else{let f=N(e.state.env),p=i.join(f);c=x(p,l)}else if(o)c=i.filter(f=>f!=="");else if(u){c=[];for(let f of i){if(f==="")continue;let p=x(f,l);c.push(...p)}}else{c=[];for(let f of i)if(f==="")c.push("");else{let p=x(f,l);c.push(...p)}for(;c.length>0&&c[c.length-1]==="";)c.pop()}return{values:await Te(e,c),quoted:!1}}function lr(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="VarNamePrefix")return null;let r=t[0].operation,s=de(e,r.prefix);if(s.length===0)return{values:[],quoted:!1};let n=W(e.state.env),a=V(e.state.env),i;if(r.star)if(a)i=s;else{let l=N(e.state.env),o=s.join(l);i=x(o,n)}else if(a)i=s;else{i=[];for(let l of s){let o=x(l,n);i.push(...o)}}return{values:i,quoted:!1}}function cr(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="ArrayKeys")return null;let r=t[0].operation,n=P(e,r.array).map(([o])=>String(o));if(n.length===0)return{values:[],quoted:!1};let a=W(e.state.env),i=V(e.state.env),l;if(r.star)if(i)l=n;else{let o=N(e.state.env),u=n.join(o);l=x(u,a)}else if(i)l=n;else{l=[];for(let o of n){let u=x(o,a);l.push(...u)}}return{values:l,quoted:!1}}async function ur(e,t,r){let s=-1;for(let p=0;p<t.length;p++){let d=t[p];if(d.type==="ParameterExpansion"&&(d.parameter==="@"||d.parameter==="*")&&!d.operation){s=p;break}}if(s===-1||t.length<=1)return null;let n=Number.parseInt(e.state.env.get("#")||"0",10),a=[];for(let p=1;p<=n;p++)a.push(e.state.env.get(String(p))||"");let i="";for(let p=0;p<s;p++)i+=await r(e,t[p]);let l="";for(let p=s+1;p<t.length;p++)l+=await r(e,t[p]);let o=W(e.state.env),u=V(e.state.env),c=Ce(e.state.env);if(n===0){let p=i+l;return{values:p?[p]:[],quoted:!1}}let f;{let p=[];for(let d=0;d<a.length;d++){let g=a[d];d===0&&(g=i+g),d===a.length-1&&(g=g+l),p.push(g)}if(u)f=p.filter(d=>d!=="");else if(c){f=[];for(let d of p){if(d==="")continue;let g=x(d,o);f.push(...g)}}else{f=[];for(let d of p)if(d==="")f.push("");else{let g=x(d,o);f.push(...g)}for(;f.length>0&&f[f.length-1]==="";)f.pop()}}return f.length===0?{values:[],quoted:!1}:{values:await Te(e,f),quoted:!1}}async function hr(e,t,r){let s=t.parts,{hasQuoted:n,hasCommandSub:a,hasArrayVar:i,hasArrayAtExpansion:l,hasParamExpansion:o,hasVarNamePrefixExpansion:u,hasIndirection:c}=ye(s),p=r.hasBraceExpansion(s)?await r.expandWordWithBracesAsync(e,t):null;if(p&&p.length>1)return ks(e,p,n);let d=await Ps(e,s,l,u,c,r);if(d!==null)return d;let g=await Is(e,s,r);if(g!==null)return g;let m=await vs(e,s,r);if(m!==null)return m;let E=await xs(e,s,r.expandPart);if(E!==null)return pr(e,E);if((a||i||o)&&!V(e.state.env)){let S=W(e.state.env),y=r.buildIfsCharClassPattern(S),b=await r.smartWordSplit(e,s,S,y,r.expandPart);return pr(e,b)}let A=await r.expandWordAsync(e,t);return $s(e,t,s,A,n,r.expandWordForGlobbing)}async function ks(e,t,r){let s=[];for(let n of t)if(!(!r&&n===""))if(!r&&!e.state.options.noglob&&ne(n,e.state.shoptOptions.extglob)){let a=await Me(e,n);s.push(...a)}else s.push(n);return{values:s,quoted:!1}}async function Ps(e,t,r,s,n,a){if(r){let i=Gn(e,t);if(i!==null)return i}{let i=Un(e,t);if(i!==null)return i}{let i=await Bn(e,t);if(i!==null)return i}{let i=await Fn(e,t,r,a.expandPart,a.expandWordPartsAsync);if(i!==null)return i}{let i=await Qn(e,t,r,a.expandPart);if(i!==null)return i}{let i=await zn(e,t,a.evaluateArithmetic);if(i!==null)return i}{let i=Zn(e,t);if(i!==null)return i}{let i=await Vn(e,t,a.expandWordPartsAsync,a.expandPart);if(i!==null)return i}{let i=await qn(e,t,a.expandWordPartsAsync,a.expandPart);if(i!==null)return i}if(s&&t.length===1&&t[0].type==="DoubleQuoted"){let i=Rs(e,t);if(i!==null)return i}{let i=await Hn(e,t,n,a.expandParameterAsync,a.expandWordPartsAsync);if(i!==null)return i}{let i=await jn(e,t);if(i!==null)return i}{let i=await Kn(e,t);if(i!==null)return i}return null}function Rs(e,t){let r=t[0];if(r.type!=="DoubleQuoted")return null;if(r.parts.length===1&&r.parts[0].type==="ParameterExpansion"&&r.parts[0].operation?.type==="VarNamePrefix"){let s=r.parts[0].operation,n=de(e,s.prefix);return s.star?{values:[n.join(N(e.state.env))],quoted:!0}:{values:n,quoted:!0}}if(r.parts.length===1&&r.parts[0].type==="ParameterExpansion"&&r.parts[0].operation?.type==="ArrayKeys"){let s=r.parts[0].operation,a=P(e,s.array).map(([i])=>String(i));return s.star?{values:[a.join(N(e.state.env))],quoted:!0}:{values:a,quoted:!0}}return null}async function Is(e,t,r){{let s=await Jn(e,t,r.evaluateArithmetic,r.expandPart);if(s!==null)return s}{let s=await Yn(e,t,r.expandPart,r.expandWordPartsAsync);if(s!==null)return s}{let s=await er(e,t,r.expandPart,r.expandWordPartsAsync);if(s!==null)return s}{let s=await tr(e,t,r.expandPart);if(s!==null)return s}return null}async function vs(e,t,r){{let s=await nr(e,t,r.expandWordPartsAsync,r.expandPart);if(s!==null)return s}{let s=await rr(e,t,r.expandWordPartsAsync,r.expandPart);if(s!==null)return s}{let s=await sr(e,t,r.expandWordPartsAsync,r.expandPart);if(s!==null)return s}{let s=await ir(e,t,r.evaluateArithmetic,r.expandPart);if(s!==null)return s}{let s=await ar(e,t);if(s!==null)return s}{let s=await or(e,t);if(s!==null)return s}{let s=lr(e,t);if(s!==null)return s}{let s=cr(e,t);if(s!==null)return s}{let s=await ur(e,t,r.expandPart);if(s!==null)return s}return null}function fr(e){if(e.type!=="DoubleQuoted")return null;for(let t=0;t<e.parts.length;t++){let r=e.parts[t];if(r.type!=="ParameterExpansion"||r.operation)continue;let s=r.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(s)return{type:"array",name:s[1],atIndex:t,isStar:s[2]==="*"};if(r.parameter==="@"||r.parameter==="*")return{type:"positional",atIndex:t,isStar:r.parameter==="*"}}return null}async function Ds(e,t,r,s){let n="";for(let l=0;l<r.atIndex;l++)n+=await s(e,t.parts[l]);let a="";for(let l=r.atIndex+1;l<t.parts.length;l++)a+=await s(e,t.parts[l]);let i;if(r.type==="array"){if(i=P(e,r.name).map(([,o])=>o),i.length===0){let o=e.state.env.get(r.name);o!==void 0&&(i=[o])}}else{let l=Number.parseInt(e.state.env.get("#")||"0",10);i=[];for(let o=1;o<=l;o++)i.push(e.state.env.get(String(o))||"")}if(r.isStar){let l=N(e.state.env),o=i.join(l);return[n+o+a]}if(i.length===0){let l=n+a;return l?[l]:[]}return i.length===1?[n+i[0]+a]:[n+i[0],...i.slice(1,-1),i[i.length-1]+a]}async function xs(e,t,r){if(t.length<2)return null;let s=!1;for(let o of t)if(fr(o)){s=!0;break}if(!s)return null;let n=W(e.state.env),a=V(e.state.env),i=[];for(let o of t){let u=fr(o);if(u&&o.type==="DoubleQuoted"){let c=await Ds(e,o,u,r);i.push(c)}else if(o.type==="DoubleQuoted"||o.type==="SingleQuoted"){let c=await r(e,o);i.push([c])}else if(o.type==="Literal")i.push([o.value]);else if(o.type==="ParameterExpansion"){let c=await r(e,o);if(a)i.push(c?[c]:[]);else{let f=x(c,n);i.push(f)}}else{let c=await r(e,o);if(a)i.push(c?[c]:[]);else{let f=x(c,n);i.push(f)}}}let l=[];for(let o of i)if(o.length!==0)if(l.length===0)l.push(...o);else{let u=l.length-1;l[u]=l[u]+o[0];for(let c=1;c<o.length;c++)l.push(o[c])}return l}async function pr(e,t){if(e.state.options.noglob)return{values:t,quoted:!1};let r=[];for(let s of t)if(ne(s,e.state.shoptOptions.extglob)){let n=await Me(e,s);r.push(...n)}else r.push(s);return{values:r,quoted:!1}}async function Me(e,t){let r=new oe(e.fs,e.state.cwd,e.state.env,{globstar:e.state.shoptOptions.globstar,nullglob:e.state.shoptOptions.nullglob,failglob:e.state.shoptOptions.failglob,dotglob:e.state.shoptOptions.dotglob,extglob:e.state.shoptOptions.extglob,globskipdots:e.state.shoptOptions.globskipdots,maxGlobOperations:e.limits.maxGlobOperations}),s=await r.expand(t);if(s.length>0)return s;if(r.hasFailglob())throw new Pe(t);return r.hasNullglob()?[]:[t]}async function $s(e,t,r,s,n,a){let i=r.some(l=>l.type==="Glob");if(!e.state.options.noglob&&i){let l=await a(e,t);if(ne(l,e.state.shoptOptions.extglob)){let u=await Me(e,l);if(u.length>0&&u[0]!==l)return{values:u,quoted:!1};if(u.length===0)return{values:[],quoted:!1}}let o=At(s);if(!V(e.state.env)){let u=W(e.state.env);return{values:x(o,u),quoted:!1}}return{values:[o],quoted:!1}}if(!n&&!e.state.options.noglob&&ne(s,e.state.shoptOptions.extglob)){let l=await a(e,t);if(ne(l,e.state.shoptOptions.extglob)){let o=await Me(e,l);if(o.length>0&&o[0]!==l)return{values:o,quoted:!1}}}if(s===""&&!n)return{values:[],quoted:!1};if(i&&!n){let l=At(s);if(!V(e.state.env)){let o=W(e.state.env);return{values:x(l,o),quoted:!1}}return{values:[l],quoted:!1}}return{values:[s],quoted:n}}async function mr(e,t){let r=t.operation;if(!r||r.type!=="DefaultValue"&&r.type!=="AssignDefault"&&r.type!=="UseAlternative")return null;let s=r.word;if(!s||s.parts.length===0)return null;let n=await te(e,t.parameter),i=await v(e,t.parameter,!1)==="",l=r.checkEmpty??!1,o;return r.type==="UseAlternative"?o=n&&!(l&&i):o=!n||l&&i,o?s.parts:null}function _s(e){return e.type==="SingleQuoted"?!0:e.type==="DoubleQuoted"?e.parts.every(r=>r.type==="Literal"):!1}async function Cs(e,t){if(t.type!=="ParameterExpansion")return null;let r=await mr(e,t);if(!r||r.length<=1)return null;let s=r.some(a=>_s(a)),n=r.some(a=>a.type==="Literal"||a.type==="ParameterExpansion"||a.type==="CommandSubstitution"||a.type==="ArithmeticExpansion");return s&&n?r:null}function Os(e){return e.type==="DoubleQuoted"||e.type==="SingleQuoted"||e.type==="Literal"?!1:e.type==="Glob"?ht(e.pattern):!(!(e.type==="ParameterExpansion"||e.type==="CommandSubstitution"||e.type==="ArithmeticExpansion")||e.type==="ParameterExpansion"&&dn(e))}async function gr(e,t,r,s,n){if(t.length===1&&t[0].type==="ParameterExpansion"){let p=t[0],d=await mr(e,p);if(d&&d.length>0&&d.length>1&&d.some(m=>m.type==="DoubleQuoted"||m.type==="SingleQuoted")&&d.some(m=>m.type==="Literal"||m.type==="ParameterExpansion"||m.type==="CommandSubstitution"||m.type==="ArithmeticExpansion"))return dr(e,d,r,s,n)}let a=[],i=!1;for(let p of t){let d=Os(p),g=p.type==="DoubleQuoted"||p.type==="SingleQuoted",m=d?await Cs(e,p):null,E=await n(e,p);a.push({value:E,isSplittable:d,isQuoted:g,mixedDefaultParts:m??void 0}),d&&(i=!0)}if(!i){let p=a.map(d=>d.value).join("");return p?[p]:[]}let l=[],o="",u=!1,c=!1,f=!1;for(let p of a)if(!p.isSplittable)c?p.isQuoted&&p.value===""?(o!==""&&l.push(o),l.push(""),u=!0,o="",c=!1,f=!0):p.value!==""?(o!==""&&l.push(o),o=p.value,c=!1,f=!1):(o+=p.value,f=!1):(o+=p.value,f=p.isQuoted&&p.value==="");else if(p.mixedDefaultParts){let d=await dr(e,p.mixedDefaultParts,r,s,n);if(d.length!==0)if(d.length===1)o+=d[0],u=!0;else{o+=d[0],l.push(o),u=!0;for(let g=1;g<d.length-1;g++)l.push(d[g]);o=d[d.length-1]}c=!1,f=!1}else{let{words:d,hadLeadingDelimiter:g,hadTrailingDelimiter:m}=Oe(p.value,r);if(f&&g&&o===""&&(l.push(""),u=!0),d.length===0)m&&(c=!0);else if(d.length===1)o+=d[0],u=!0,c=m;else{o+=d[0],l.push(o),u=!0;for(let E=1;E<d.length-1;E++)l.push(d[E]);o=d[d.length-1],c=m}f=!1}return o!==""?l.push(o):l.length===0&&u&&l.push(""),l}function Ls(e,t){return e.length>0&&t.includes(e[0])}async function dr(e,t,r,s,n){let a=[];for(let c of t){let p=!(c.type==="DoubleQuoted"||c.type==="SingleQuoted"),d=await n(e,c);a.push({value:d,isSplittable:p})}let i=[],l="",o=!1,u=!1;for(let c of a)if(!c.isSplittable)u&&c.value!==""?(l!==""&&i.push(l),l=c.value,u=!1):l+=c.value;else{Ls(c.value,r)&&l!==""&&(i.push(l),l="",o=!0);let{words:p,hadTrailingDelimiter:d}=Oe(c.value,r);if(p.length===0)d&&(u=!0);else if(p.length===1)l+=p[0],o=!0,u=d;else{l+=p[0],i.push(l),o=!0;for(let g=1;g<p.length-1;g++)i.push(p[g]);l=p[p.length-1],u=d}}return l!==""?i.push(l):i.length===0&&o&&i.push(""),i}function yr(e){switch(e.type){case"Literal":return e.value;case"SingleQuoted":return e.value;case"Escaped":return e.value;default:return null}}function Er(e){switch(e.type){case"SingleQuoted":case"Escaped":case"DoubleQuoted":return!0;case"Literal":return e.value==="";default:return!1}}function we(e,t,r){if(e.length>t)throw new B(`${r}: string length limit exceeded (${t} bytes)`,"string_length")}async function X(e,t,r=!1){let s=[];for(let n of t)s.push(await U(e,n,r));return s.join("")}function Ws(e){return Er(e)}function El(e){if(e.parts.length===0)return!0;for(let t of e.parts)if(!Ws(t))return!1;return!0}function Ts(e,t,r=!1){let s=yr(t);if(s!==null)return s;switch(t.type){case"TildeExpansion":return r?t.user===null?"~":`~${t.user}`:t.user===null?e.state.env.get("HOME")??"/home/user":t.user==="root"?"/root":`~${t.user}`;case"Glob":return wt(e,t.pattern);default:return null}}async function kt(e,t){return Pt(e,t)}async function Al(e,t){let r=[];for(let s of t.parts)if(s.type==="Escaped")r.push(`\\${s.value}`);else if(s.type==="SingleQuoted")r.push(s.value);else if(s.type==="DoubleQuoted"){let n=await X(e,s.parts);r.push(n)}else if(s.type==="TildeExpansion"){let n=await U(e,s);r.push(St(n))}else r.push(await U(e,s));return r.join("")}async function Sl(e,t){let r=[];for(let s of t.parts)if(s.type==="Escaped"){let n=s.value;"()|*?[]".includes(n)?r.push(`\\${n}`):r.push(n)}else if(s.type==="SingleQuoted")r.push(K(s.value));else if(s.type==="DoubleQuoted"){let n=await X(e,s.parts);r.push(K(n))}else r.push(await U(e,s));return r.join("")}async function Ar(e,t){let r=[];for(let s of t.parts)if(s.type==="SingleQuoted")r.push(K(s.value));else if(s.type==="Escaped"){let n=s.value;"*?[]\\()|".includes(n)?r.push(`\\${n}`):r.push(n)}else if(s.type==="DoubleQuoted"){let n=await X(e,s.parts);r.push(K(n))}else s.type==="Glob"?Ln(s.pattern)?r.push(await Tn(e,s.pattern)):r.push(wt(e,s.pattern)):s.type==="Literal"?r.push(s.value):r.push(await U(e,s));return r.join("")}function qe(e){for(let t of e)if(t.type==="BraceExpansion"||t.type==="DoubleQuoted"&&qe(t.parts))return!0;return!1}var Ms=1e4,Nt=1e5;async function Sr(e,t,r={count:0}){if(r.count>Nt)return[[]];let s=[[]];for(let n of t)if(n.type==="BraceExpansion"){let a=[],i=!1,l="";for(let c of n.items)if(c.type==="Range"){let f=Et(c.start,c.end,c.step,c.startStr,c.endStr);if(f.expanded)for(let p of f.expanded)r.count++,a.push(p);else{i=!0,l=f.literal;break}}else{let f=await Sr(e,c.word.parts,r);for(let p of f){r.count++;let d=[];for(let g of p)typeof g=="string"?d.push(g):d.push(await U(e,g));a.push(d.join(""))}}if(i){for(let c of s)r.count++,c.push(l);continue}if(s.length*a.length>Ms||r.count>Nt)return s;let u=[];for(let c of s)for(let f of a){if(r.count++,r.count>Nt)return u.length>0?u:s;u.push([...c,f])}s=u}else for(let a of s)r.count++,a.push(n);return s}async function br(e,t){let r=t.parts;if(!qe(r))return[await kt(e,t)];let s=await Sr(e,r),n=[];for(let a of s){let i=[];for(let l of a)typeof l=="string"?i.push(l):i.push(await U(e,l));n.push(Mn(e,i.join("")))}return n}function Vs(){return{expandWordAsync:Pt,expandWordForGlobbing:Ar,expandWordWithBracesAsync:br,expandWordPartsAsync:X,expandPart:U,expandParameterAsync:Ve,hasBraceExpansion:qe,evaluateArithmetic:R,buildIfsCharClassPattern:yn,smartWordSplit:gr}}async function bl(e,t){return hr(e,t,Vs())}function qs(e){for(let t of e){if(t.type==="ParameterExpansion")return t.parameter;if(t.type==="Literal")return t.value}return""}function Bs(e,t){if(Number.parseInt(e.state.env.get("#")||"0",10)<2)return!1;function s(n){for(let a of n)if(a.type==="DoubleQuoted"){for(let i of a.parts)if(i.type==="ParameterExpansion"&&i.parameter==="@"&&!i.operation)return!0}return!1}return s(t.parts)}async function wl(e,t){if(Bs(e,t))return{error:`bash: $@: ambiguous redirect
|
|
70
|
-
`};let r=t.parts,{hasQuoted:s}=ye(r);if(qe(r)&&(await
|
|
71
|
-
`};let n=await
|
|
72
|
-
`}}if(s||e.state.options.noglob)return{target:n};let o=await
|
|
62
|
+
`,""):e.state.env.get(`${i}_${g}`)||""}let c=e.state.env.get(`${i}_${u}`);if(c!==void 0)return c;if(u===0){let f=e.state.env.get(i);if(f!==void 0)return f}if(r&&e.state.options.nounset)throw new H(`${i}[${u}]`);return""}if(/^[1-9][0-9]*$/.test(t)){let i=e.state.env.get(t);if(i===void 0&&r&&e.state.options.nounset)throw new H(t);return i||""}if(L(e,t)){let i=fe(e,t);if(i===void 0)return"";if(i!==t)return await D(e,i,r,s);let l=e.state.env.get(t);if((l===void 0||l==="")&&r&&e.state.options.nounset)throw new H(t);return l||""}let a=e.state.env.get(t);if(a!==void 0)return e.state.tempEnvBindings?.some(i=>i.has(t))&&(e.state.accessedTempEnvVars=e.state.accessedTempEnvVars||new Set,e.state.accessedTempEnvVars.add(t)),a;if(Se(e,t)){let i=e.state.env.get(`${t}_0`);return i!==void 0?i:""}if(r&&e.state.options.nounset)throw new H(t);return""}async function te(e,t){if(new Set(["?","$","#","_","-","0","PPID","UID","EUID","RANDOM","SECONDS","BASH_VERSION","!","BASHPID","LINENO"]).has(t))return!0;if(t==="@"||t==="*")return Number.parseInt(e.state.env.get("#")||"0",10)>0;if(t==="PWD"||t==="OLDPWD")return e.state.env.has(t);let s=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(s){let n=s[1],a=s[2];if(L(e,n)){let o=fe(e,n);if(o&&o!==n){if(o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/))return!1;n=o}}if(a==="@"||a==="*")return P(e,n).length>0?!0:e.state.env.has(n);if(e.state.associativeArrays?.has(n)){let o=_e(a);return e.state.env.has(`${n}_${o}`)}let l;if(/^-?\d+$/.test(a))l=Number.parseInt(a,10);else try{let o=new M,u=T(o,a);l=await R(e,u.expression)}catch{let o=e.state.env.get(a);l=o?Number.parseInt(o,10):0,Number.isNaN(l)&&(l=0)}if(l<0){let o=P(e,n);if(o.length===0)return!1;let c=Math.max(...o.map(([f])=>typeof f=="number"?f:0))+1+l;return c<0?!1:e.state.env.has(`${n}_${c}`)}return e.state.env.has(`${n}_${l}`)}if(L(e,t)){let n=fe(e,t);return n===void 0||n===t?e.state.env.has(t):te(e,n)}return!!(e.state.env.has(t)||Se(e,t))}async function Sn(e,t){let r="",s=0;for(;s<t.length;){if(t[s]==="$"){if(t[s+1]==="{"){let n=1,a=s+2;for(;a<t.length&&n>0;)t[a]==="{"?n++:t[a]==="}"&&n--,a++;r+=t.slice(s,a),s=a;continue}if(t[s+1]==="("){let n=1,a=s+2;for(;a<t.length&&n>0;)t[a]==="("?n++:t[a]===")"&&n--,a++;r+=t.slice(s,a),s=a;continue}if(/[a-zA-Z_]/.test(t[s+1]||"")){let n=s+1;for(;n<t.length&&/[a-zA-Z0-9_]/.test(t[n]);)n++;let a=t.slice(s+1,n),i=await D(e,a);r+=i,s=n;continue}if(/[0-9]/.test(t[s+1]||"")){let n=s+1;for(;n<t.length&&/[0-9]/.test(t[n]);)n++;let a=t.slice(s+1,n),i=await D(e,a);r+=i,s=n;continue}if(/[*@#?\-!$]/.test(t[s+1]||"")){let n=t[s+1],a=await D(e,n);r+=a,s+=2;continue}}if(t[s]==='"'){for(r+='"',s++;s<t.length&&t[s]!=='"';)if(t[s]==="$"&&/[a-zA-Z_]/.test(t[s+1]||"")){let n=s+1;for(;n<t.length&&/[a-zA-Z0-9_]/.test(t[n]);)n++;let a=t.slice(s+1,n),i=await D(e,a);r+=i,s=n}else t[s]==="\\"?(r+=t[s],s++,s<t.length&&(r+=t[s],s++)):(r+=t[s],s++);s<t.length&&(r+='"',s++);continue}r+=t[s],s++}return r}async function Et(e,t){let r=t,s=t.startsWith('"')&&t.endsWith('"'),n=t.startsWith("'")&&t.endsWith("'");if((s||n)&&(r=t.slice(1,-1)),n)return r;let a="",i=0;for(;i<r.length;)if(r[i]==="$")if(r[i+1]==="("){let l=1,o=i+2;for(;o<r.length&&l>0;)r[o]==="("&&r[o-1]==="$"||r[o]==="("?l++:r[o]===")"&&l--,o++;let u=r.slice(i+2,o-1);if(e.execFn){let c=await e.execFn(u);a+=c.stdout.replace(/\n+$/,""),c.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+c.stderr)}i=o}else if(r[i+1]==="{"){let l=1,o=i+2;for(;o<r.length&&l>0;)r[o]==="{"?l++:r[o]==="}"&&l--,o++;let u=r.slice(i+2,o-1),c=await D(e,u);a+=c,i=o}else if(/[a-zA-Z_]/.test(r[i+1]||"")){let l=i+1;for(;l<r.length&&/[a-zA-Z0-9_]/.test(r[l]);)l++;let o=r.slice(i+1,l),u=await D(e,o);a+=u,i=l}else a+=r[i],i++;else if(r[i]==="`"){let l=i+1;for(;l<r.length&&r[l]!=="`";)l++;let o=r.slice(i+1,l);if(e.execFn){let u=await e.execFn(o);a+=u.stdout.replace(/\n+$/,""),u.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+u.stderr)}i=l+1}else a+=r[i],i++;return a}var Le=1e4;function us(e,t,r,s,n){let a=r??1;a===0&&(a=1);let i=Math.abs(a),l=[],o=0;s?.match(/^-?0\d/)&&(o=Math.max(o,s.replace(/^-/,"").length)),n?.match(/^-?0\d/)&&(o=Math.max(o,n.replace(/^-/,"").length));let u=c=>{if(o>0){let f=c<0,p=String(Math.abs(c)).padStart(o,"0");return f?`-${p}`:p}return String(c)};if(e<=t)for(let c=e,f=0;c<=t&&f<Le;c+=i,f++)l.push(u(c));else for(let c=e,f=0;c>=t&&f<Le;c-=i,f++)l.push(u(c));return l}function fs(e,t,r){let s=r??1;s===0&&(s=1);let n=e.charCodeAt(0),a=t.charCodeAt(0),i=Math.abs(s),l=e>="A"&&e<="Z",o=e>="a"&&e<="z",u=t>="A"&&t<="Z",c=t>="a"&&t<="z";if(l&&c||o&&u){let p=r!==void 0?`..${r}`:"";throw new It(`{${e}..${t}${p}}: invalid sequence`)}let f=[];if(n<=a)for(let p=n,d=0;p<=a&&d<Le;p+=i,d++)f.push(String.fromCharCode(p));else for(let p=n,d=0;p>=a&&d<Le;p-=i,d++)f.push(String.fromCharCode(p));return f}function At(e,t,r,s,n){let a=r!==void 0?`..${r}`:"";return typeof e=="number"&&typeof t=="number"?{expanded:us(e,t,r,s,n),literal:`{${e}..${t}${a}}`}:typeof e=="string"&&typeof t=="string"?{expanded:fs(e,t,r),literal:`{${e}..${t}${a}}`}:{expanded:null,literal:`{${e}..${t}${a}}`}}function bn(e){if(e.statements.length!==1)return null;let t=e.statements[0];if(t.operators.length!==0||t.pipelines.length!==1)return null;let r=t.pipelines[0];if(r.negated||r.commands.length!==1)return null;let s=r.commands[0];if(s.type!=="SimpleCommand")return null;let n=s;if(n.name!==null||n.args.length!==0||n.assignments.length!==0||n.redirections.length!==1)return null;let a=n.redirections[0];return a.operator!=="<"||a.target.type!=="Word"?null:{target:a.target}}function ne(e,t){return!!(/[*?[]/.test(e)||t&&/[@*+?!]\(/.test(e))}function St(e){let t="",r=0;for(;r<e.length;)e[r]==="\\"&&r+1<e.length?(t+=e[r+1],r+=2):(t+=e[r],r++);return t}function K(e){return e.replace(/([*?[\]\\()|])/g,"\\$1")}function bt(e){return e.replace(/[\\^$.*+?()[\]{}|]/g,"\\$&")}function I(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function k(e,t,r=!1){let s="",n=0;for(;n<e.length;){let a=e[n];if(r&&(a==="@"||a==="*"||a==="+"||a==="?"||a==="!")&&n+1<e.length&&e[n+1]==="("){let i=ps(e,n+1);if(i!==-1){let l=e.slice(n+2,i),u=hs(l).map(f=>k(f,t,r)),c=u.length>0?u.join("|"):"(?:)";a==="@"?s+=`(?:${c})`:a==="*"?s+=`(?:${c})*`:a==="+"?s+=`(?:${c})+`:a==="?"?s+=`(?:${c})?`:a==="!"&&(s+=`(?!(?:${c})$).*`),n=i+1;continue}}if(a==="\\")if(n+1<e.length){let i=e[n+1];/[\\^$.|+(){}[\]*?]/.test(i)?s+=`\\${i}`:s+=i,n+=2}else s+="\\\\",n++;else if(a==="*")s+=t?".*":".*?",n++;else if(a==="?")s+=".",n++;else if(a==="["){let i=ds(e,n);if(i===-1)s+="\\[",n++;else{let l=e.slice(n+1,i);s+=ms(l),n=i+1}}else/[\^$.|+(){}]/.test(a)?(s+=`\\${a}`,n++):(s+=a,n++)}return s}function ps(e,t){let r=1,s=t+1;for(;s<e.length&&r>0;){let n=e[s];if(n==="\\"){s+=2;continue}if(n==="(")r++;else if(n===")"&&(r--,r===0))return s;s++}return-1}function hs(e){let t=[],r="",s=0,n=0;for(;n<e.length;){let a=e[n];if(a==="\\"){r+=a,n+1<e.length?(r+=e[n+1],n+=2):n++;continue}a==="("?(s++,r+=a):a===")"?(s--,r+=a):a==="|"&&s===0?(t.push(r),r=""):r+=a,n++}return t.push(r),t}function ds(e,t){let r=t+1;for(r<e.length&&e[r]==="^"&&r++,r<e.length&&e[r]==="]"&&r++;r<e.length;){if(e[r]==="\\"&&r+1<e.length){r+=2;continue}if(e[r]==="]")return r;if(e[r]==="'"){let s=e.indexOf("'",r+1);if(s!==-1){r=s+1;continue}}if(e[r]==="["&&r+1<e.length&&e[r+1]===":"){let s=e.indexOf(":]",r+2);if(s!==-1){r=s+2;continue}}r++}return-1}function ms(e){let t="[",r=0;for((e[0]==="^"||e[0]==="!")&&(t+="^",r++);r<e.length;){if(e[r]==="'"){let n=e.indexOf("'",r+1);if(n!==-1){let a=e.slice(r+1,n);for(let i of a)i==="\\"?t+="\\\\":i==="]"?t+="\\]":i==="^"&&t==="["?t+="\\^":t+=i;r=n+1;continue}}if(e[r]==="["&&r+1<e.length&&e[r+1]===":"){let n=e.indexOf(":]",r+2);if(n!==-1){let a=e.slice(r+2,n);t+=ys(a),r=n+2;continue}}let s=e[r];s==="\\"?r+1<e.length?(t+=`\\${e[r+1]}`,r+=2):(t+="\\\\",r++):s==="-"&&r>0&&r<e.length-1?(t+="-",r++):s==="^"&&r===0?(t+="^",r++):(s==="]"&&r===0?t+="\\]":t+=s,r++)}return t+="]",t}var gs=new Map([["alnum","a-zA-Z0-9"],["alpha","a-zA-Z"],["ascii","\\x00-\\x7F"],["blank"," \\t"],["cntrl","\\x00-\\x1F\\x7F"],["digit","0-9"],["graph","!-~"],["lower","a-z"],["print"," -~"],["punct","!-/:-@\\[-`{-~"],["space"," \\t\\n\\r\\f\\v"],["upper","A-Z"],["word","a-zA-Z0-9_"],["xdigit","0-9A-Fa-f"]]);function ys(e){return gs.get(e)??""}function se(e,t,r,s){if(r==="prefix")return O(`^${t}`,"s").replace(e,"");let n=O(`${t}$`,"s");if(s)return n.replace(e,"");for(let a=e.length;a>=0;a--){let i=e.slice(a);if(n.test(i))return e.slice(0,a)}return e}function de(e,t){let r=Array.from(e.state.env.keys()),s=new Set,n=e.state.associativeArrays??new Set,a=new Set;for(let l of r){let o=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)_\d+$/);o&&a.add(o[1]);let u=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)__length$/);u&&a.add(u[1])}let i=l=>{for(let o of n){let u=`${o}_`;if(l.startsWith(u)&&l!==o)return!0}return!1};for(let l of r)if(l.startsWith(t))if(l.includes("__")){let o=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)__length$/);o?.[1].startsWith(t)&&s.add(o[1])}else if(/_\d+$/.test(l)){let o=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)_\d+$/);o?.[1].startsWith(t)&&s.add(o[1])}else i(l)||s.add(l);return[...s].sort()}function Es(e,t){let r=(a,i=2)=>String(a).padStart(i,"0");if(e===""){let a=r(t.getHours()),i=r(t.getMinutes()),l=r(t.getSeconds());return`${a}:${i}:${l}`}let s="",n=0;for(;n<e.length;)if(e[n]==="%"){if(n+1>=e.length){s+="%",n++;continue}let a=e[n+1];switch(a){case"H":s+=r(t.getHours());break;case"M":s+=r(t.getMinutes());break;case"S":s+=r(t.getSeconds());break;case"d":s+=r(t.getDate());break;case"m":s+=r(t.getMonth()+1);break;case"Y":s+=t.getFullYear();break;case"y":s+=r(t.getFullYear()%100);break;case"I":{let i=t.getHours()%12;i===0&&(i=12),s+=r(i);break}case"p":s+=t.getHours()<12?"AM":"PM";break;case"P":s+=t.getHours()<12?"am":"pm";break;case"%":s+="%";break;case"a":{s+=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"][t.getDay()];break}case"b":{s+=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][t.getMonth()];break}default:s+=`%${a}`}n+=2}else s+=e[n],n++;return s}function be(e,t){let r="",s=0,n=e.state.env.get("USER")||e.state.env.get("LOGNAME")||"user",a=e.state.env.get("HOSTNAME")||"localhost",i=a.split(".")[0],l=e.state.env.get("PWD")||"/",o=e.state.env.get("HOME")||"/",u=l.startsWith(o)?`~${l.slice(o.length)}`:l,c=l.split("/").pop()||l,f=new Date,p=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],d=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],g=e.state.env.get("__COMMAND_NUMBER")||"1";for(;s<t.length;){let m=t[s];if(m==="\\"){if(s+1>=t.length){r+="\\",s++;continue}let E=t[s+1];if(E>="0"&&E<="7"){let A="",S=s+1;for(;S<t.length&&S<s+4&&t[S]>="0"&&t[S]<="7";)A+=t[S],S++;let y=Number.parseInt(A,8)%256;r+=String.fromCharCode(y),s=S;continue}switch(E){case"\\":r+="\\",s+=2;break;case"a":r+="\x07",s+=2;break;case"e":r+="\x1B",s+=2;break;case"n":r+=`
|
|
63
|
+
`,s+=2;break;case"r":r+="\r",s+=2;break;case"$":r+="$",s+=2;break;case"[":case"]":s+=2;break;case"u":r+=n,s+=2;break;case"h":r+=i,s+=2;break;case"H":r+=a,s+=2;break;case"w":r+=u,s+=2;break;case"W":r+=c,s+=2;break;case"d":{let A=String(f.getDate()).padStart(2," ");r+=`${p[f.getDay()]} ${d[f.getMonth()]} ${A}`,s+=2;break}case"t":{let A=String(f.getHours()).padStart(2,"0"),S=String(f.getMinutes()).padStart(2,"0"),y=String(f.getSeconds()).padStart(2,"0");r+=`${A}:${S}:${y}`,s+=2;break}case"T":{let A=f.getHours()%12;A===0&&(A=12);let S=String(A).padStart(2,"0"),y=String(f.getMinutes()).padStart(2,"0"),b=String(f.getSeconds()).padStart(2,"0");r+=`${S}:${y}:${b}`,s+=2;break}case"@":{let A=f.getHours()%12;A===0&&(A=12);let S=String(A).padStart(2,"0"),y=String(f.getMinutes()).padStart(2,"0"),b=f.getHours()<12?"AM":"PM";r+=`${S}:${y} ${b}`,s+=2;break}case"A":{let A=String(f.getHours()).padStart(2,"0"),S=String(f.getMinutes()).padStart(2,"0");r+=`${A}:${S}`,s+=2;break}case"D":if(s+2<t.length&&t[s+2]==="{"){let A=t.indexOf("}",s+3);if(A!==-1){let S=t.slice(s+3,A);r+=Es(S,f),s=A+1}else r+="\\D",s+=2}else r+="\\D",s+=2;break;case"s":r+="bash",s+=2;break;case"v":r+="5.0",s+=2;break;case"V":r+="5.0.0",s+=2;break;case"j":r+="0",s+=2;break;case"l":r+="tty",s+=2;break;case"#":r+=g,s+=2;break;case"!":r+=g,s+=2;break;case"x":r+="\\x",s+=2;break;default:r+=`\\${E}`,s+=2}}else r+=m,s++}return r}function le(e){if(e==="")return"''";if(/[\n\r\t\x00-\x1f\x7f']/.test(e)){let r="$'";for(let s of e)switch(s){case"'":r+="\\'";break;case"\\":r+="\\\\";break;case`
|
|
64
|
+
`:r+="\\n";break;case"\r":r+="\\r";break;case" ":r+="\\t";break;default:{let n=s.charCodeAt(0);n<32||n===127?r+=`\\${n.toString(8).padStart(3,"0")}`:r+=s}}return`${r}'`}return`'${e}'`}function ha(e,t){e.state.readonlyVars=e.state.readonlyVars||new Set,e.state.readonlyVars.add(t)}function wt(e,t){return e.state.readonlyVars?.has(t)??!1}function da(e,t,r="bash"){if(wt(e,t)){let s=`${r}: ${t}: readonly variable
|
|
65
|
+
`;throw new j(1,"",s)}return null}function ma(e,t){let r=e.state.exportedVars?.has(t)??!1;if(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(t),e.state.localScopes.length>0&&e.state.localScopes[e.state.localScopes.length-1].has(t)&&!r){for(e.state.localExportedVars||(e.state.localExportedVars=[]);e.state.localExportedVars.length<e.state.localScopes.length;)e.state.localExportedVars.push(new Set);e.state.localExportedVars[e.state.localExportedVars.length-1].add(t)}}function ga(e,t){e.state.exportedVars?.delete(t)}function ce(e,t){if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t))return"";let r="",s=e.state.env.has(`${t}__length`)||Array.from(e.state.env.keys()).some(a=>a.startsWith(`${t}_`)&&/^[0-9]+$/.test(a.slice(t.length+1))),n=e.state.associativeArrays?.has(t)??!1;return s&&!n&&(r+="a"),n&&(r+="A"),e.state.integerVars?.has(t)&&(r+="i"),L(e,t)&&(r+="n"),wt(e,t)&&(r+="r"),e.state.exportedVars?.has(t)&&(r+="x"),r}async function wn(e,t,r,s){return(r.isUnset||t.checkEmpty&&r.isEmpty)&&t.word?s(e,t.word.parts,r.inDoubleQuotes):r.effectiveValue}async function Nn(e,t,r,s,n){if((s.isUnset||r.checkEmpty&&s.isEmpty)&&r.word){let i=await n(e,r.word.parts,s.inDoubleQuotes),l=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(l){let[,o,u]=l,c;if(/^\d+$/.test(u))c=Number.parseInt(u,10);else{try{let p=new M,d=T(p,u);c=await R(e,d.expression)}catch{let p=e.state.env.get(u);c=p?Number.parseInt(p,10):0}Number.isNaN(c)&&(c=0)}e.state.env.set(`${o}_${c}`,i);let f=Number.parseInt(e.state.env.get(`${o}__length`)||"0",10);c>=f&&e.state.env.set(`${o}__length`,String(c+1))}else e.state.env.set(t,i);return i}return s.effectiveValue}async function kn(e,t,r,s,n){if(s.isUnset||r.checkEmpty&&s.isEmpty){let i=r.word?await n(e,r.word.parts,s.inDoubleQuotes):`${t}: parameter null or not set`;throw new j(1,"",`bash: ${i}
|
|
66
|
+
`)}return s.effectiveValue}async function Pn(e,t,r,s){return!(r.isUnset||t.checkEmpty&&r.isEmpty)&&t.word?s(e,t.word.parts,r.inDoubleQuotes):""}async function Rn(e,t,r,s,n){let a="",i=e.state.shoptOptions.extglob;if(r.pattern)for(let o of r.pattern.parts)if(o.type==="Glob")a+=k(o.pattern,r.greedy,i);else if(o.type==="Literal")a+=k(o.value,r.greedy,i);else if(o.type==="SingleQuoted"||o.type==="Escaped")a+=I(o.value);else if(o.type==="DoubleQuoted"){let u=await s(e,o.parts);a+=I(u)}else if(o.type==="ParameterExpansion"){let u=await n(e,o);a+=k(u,r.greedy,i)}else{let u=await n(e,o);a+=I(u)}if(r.side==="prefix")return O(`^${a}`,"s").replace(t,"");let l=O(`${a}$`,"s");if(r.greedy)return l.replace(t,"");for(let o=t.length;o>=0;o--){let u=t.slice(o);if(l.test(u))return t.slice(0,o)}return t}async function In(e,t,r,s,n){let a="",i=e.state.shoptOptions.extglob;if(r.pattern)for(let u of r.pattern.parts)if(u.type==="Glob")a+=k(u.pattern,!0,i);else if(u.type==="Literal")a+=k(u.value,!0,i);else if(u.type==="SingleQuoted"||u.type==="Escaped")a+=I(u.value);else if(u.type==="DoubleQuoted"){let c=await s(e,u.parts);a+=I(c)}else if(u.type==="ParameterExpansion"){let c=await n(e,u);a+=k(c,!0,i)}else{let c=await n(e,u);a+=I(c)}let l=r.replacement?await s(e,r.replacement.parts):"";if(r.anchor==="start"?a=`^${a}`:r.anchor==="end"&&(a=`${a}$`),a==="")return t;let o=r.all?"gs":"s";try{let u=O(a,o);if(r.all){let c="",f=0,p=u.exec(t);for(;p!==null&&!(p[0].length===0&&p.index===t.length);)c+=t.slice(f,p.index)+l,f=p.index+p[0].length,p[0].length===0&&f++,p=u.exec(t);return c+=t.slice(f),c}return u.replace(t,l)}catch{return t}}function Dn(e,t,r){let s=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(s){let n=s[1],a=P(e,n);return a.length>0?String(a.length):e.state.env.get(n)!==void 0?"1":"0"}if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t)&&Se(e,t)){if(t==="FUNCNAME"){let a=e.state.funcNameStack?.[0]||"";return String([...a].length)}if(t==="BASH_LINENO"){let a=e.state.callLineStack?.[0];return String(a!==void 0?[...String(a)].length:0)}let n=e.state.env.get(`${t}_0`)||"";return String([...n].length)}return String([...r].length)}async function vn(e,t,r,s){let n=await R(e,s.offset.expression),a=s.length?await R(e,s.length.expression):void 0;if(t==="@"||t==="*"){let u=Number.parseInt(e.state.env.get("#")||"0",10),c=[];for(let g=1;g<=u;g++)c.push(e.state.env.get(String(g))||"");let f=e.state.env.get("0")||"bash",p,d;if(n<=0)if(p=[f,...c],n<0){if(d=p.length+n,d<0)return""}else d=0;else p=c,d=n-1;if(d<0||d>=p.length)return"";if(a!==void 0){let g=a<0?p.length+a:d+a;return p.slice(d,Math.max(d,g)).join(" ")}return p.slice(d).join(" ")}let i=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(i){let u=i[1];if(e.state.associativeArrays?.has(u))throw new j(1,"",`bash: \${${u}[@]: 0: 3}: bad substitution
|
|
67
|
+
`);let c=P(e,u),f=0;if(n<0){if(c.length>0){let p=c[c.length-1][0],g=(typeof p=="number"?p:0)+1+n;if(g<0||(f=c.findIndex(([m])=>typeof m=="number"&&m>=g),f<0))return""}}else if(f=c.findIndex(([p])=>typeof p=="number"&&p>=n),f<0)return"";if(a!==void 0){if(a<0)throw new C(`${i[1]}[@]: substring expression < 0`);return c.slice(f,f+a).map(([,p])=>p).join(" ")}return c.slice(f).map(([,p])=>p).join(" ")}let l=[...r],o=n;if(o<0&&(o=Math.max(0,l.length+o)),a!==void 0){if(a<0){let u=l.length+a;return l.slice(o,Math.max(o,u)).join("")}return l.slice(o,o+a).join("")}return l.slice(o).join("")}async function xn(e,t,r,s,n){if(r.pattern){let a=e.state.shoptOptions.extglob,i="";for(let f of r.pattern.parts)if(f.type==="Glob")i+=k(f.pattern,!0,a);else if(f.type==="Literal")i+=k(f.value,!0,a);else if(f.type==="SingleQuoted"||f.type==="Escaped")i+=I(f.value);else if(f.type==="DoubleQuoted"){let p=await s(e,f.parts);i+=I(p)}else if(f.type==="ParameterExpansion"){let p=await n(e,f);i+=k(p,!0,a)}let l=O(`^(?:${i})$`),o=r.direction==="upper"?f=>f.toUpperCase():f=>f.toLowerCase(),u="",c=!1;for(let f of t)!r.all&&c?u+=f:l.test(f)?(u+=o(f),c=!0):u+=f;return u}return r.direction==="upper"?r.all?t.toUpperCase():t.charAt(0).toUpperCase()+t.slice(1):r.all?t.toLowerCase():t.charAt(0).toLowerCase()+t.slice(1)}function $n(e,t,r,s,n){let a=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(a&&n.operator==="Q")return P(e,a[1]).map(([,u])=>le(u)).join(" ");if(a&&n.operator==="a")return ce(e,a[1]);let i=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[.+\]$/);if(i&&n.operator==="a")return ce(e,i[1]);switch(n.operator){case"Q":return s?"":le(r);case"P":return be(e,r);case"a":return ce(e,t);case"A":return s?"":`${t}=${le(r)}`;case"E":return r.replace(/\\([\\abefnrtv'"?])/g,(l,o)=>{switch(o){case"\\":return"\\";case"a":return"\x07";case"b":return"\b";case"e":return"\x1B";case"f":return"\f";case"n":return`
|
|
68
|
+
`;case"r":return"\r";case"t":return" ";case"v":return"\v";case"'":return"'";case'"':return'"';case"?":return"?";default:return o}});case"K":case"k":return s?"":le(r);case"u":return r.charAt(0).toUpperCase()+r.slice(1);case"U":return r.toUpperCase();case"L":return r.toLowerCase();default:return r}}async function _n(e,t,r,s,n,a,i=!1){if(L(e,t))return Ae(e,t)||"";let l=/^[a-zA-Z_][a-zA-Z0-9_]*\[([@*])\]$/.test(t);if(s){if(n.innerOp?.type==="UseAlternative")return"";throw new re(`\${!${t}}`)}let o=r;if(l&&(o===""||o.includes(" ")))throw new re(`\${!${t}}`);let u=o.match(/^[a-zA-Z_][a-zA-Z0-9_]*\[(.+)\]$/);if(u&&u[1].includes("~"))throw new re(`\${!${t}}`);if(n.innerOp){let c={type:"ParameterExpansion",parameter:o,operation:n.innerOp};return a(e,c,i)}return await D(e,o)}function Cn(e,t){let s=P(e,t.array).map(([n])=>String(n));return t.star?s.join(N(e.state.env)):s.join(" ")}function On(e,t){let r=de(e,t.prefix);return t.star?r.join(N(e.state.env)):r.join(" ")}function Ln(e,t,r,s){let n=Number.parseInt(e.state.env.get("#")||"0",10),a=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(t==="*")return{isEmpty:n===0,effectiveValue:r};if(t==="@")return{isEmpty:n===0||n===1&&e.state.env.get("1")==="",effectiveValue:r};if(a){let[,i,l]=a,o=P(e,i);if(o.length===0)return{isEmpty:!0,effectiveValue:""};if(l==="*"){let u=N(e.state.env),c=o.map(([,f])=>f).join(u);return{isEmpty:s?c==="":!1,effectiveValue:c}}return{isEmpty:o.length===1&&o.every(([,u])=>u===""),effectiveValue:o.map(([,u])=>u).join(" ")}}return{isEmpty:r==="",effectiveValue:r}}function Wn(e){let t=0;for(;t<e.length;){let r=e[t];if(r==="\\"&&t+1<e.length){t+=2;continue}if(r==="'"){let s=e.indexOf("'",t+1);if(s!==-1){t=s+1;continue}}if(r==="$"&&t+1<e.length&&e[t+1]==="("||r==="`")return!0;t++}return!1}function Tn(e,t){let r=1,s=t,n=!1,a=!1;for(;s<e.length&&r>0;){let i=e[s];if(i==="\\"&&!n&&s+1<e.length){s+=2;continue}if(i==="'"&&!a){n=!n,s++;continue}if(i==='"'&&!n){a=!a,s++;continue}if(!n&&!a){if(i==="(")r++;else if(i===")"&&(r--,r===0))return s}s++}return-1}async function We(e,t){let r=new M,s;try{s=r.parse(t)}catch{return""}let n=e.state.bashPid;e.state.bashPid=e.state.nextVirtualPid++;let a=new Map(e.state.env),i=e.state.cwd,l=e.state.suppressVerbose;e.state.suppressVerbose=!0;try{let o=await e.executeScript(s),u=o.exitCode;return e.state.env=a,e.state.cwd=i,e.state.suppressVerbose=l,e.state.lastExitCode=u,e.state.env.set("?",String(u)),o.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+o.stderr),e.state.bashPid=n,o.stdout.replace(/\n+$/,"")}catch(o){if(e.state.env=a,e.state.cwd=i,e.state.bashPid=n,e.state.suppressVerbose=l,o instanceof B)throw o;return o instanceof j?(e.state.lastExitCode=o.exitCode,e.state.env.set("?",String(o.exitCode)),o.stdout?.replace(/\n+$/,"")??""):""}}function Nt(e,t){let r="",s=0;for(;s<t.length;){let n=t[s];if(n==="'"){let a=t.indexOf("'",s+1);if(a!==-1){let i=t.slice(s+1,a);r+=K(i),s=a+1;continue}}if(n==='"'){let a=-1,i=s+1;for(;i<t.length;){if(t[i]==="\\"){i+=2;continue}if(t[i]==='"'){a=i;break}i++}if(a!==-1){let l=t.slice(s+1,a),o=As(e,l);r+=K(o),s=a+1;continue}}if(n==="$"&&s+1<t.length){let a=t[s+1];if(a==="{"){let i=t.indexOf("}",s+2);if(i!==-1){let l=t.slice(s+2,i);r+=e.state.env.get(l)??"",s=i+1;continue}}else if(/[a-zA-Z_]/.test(a)){let i=s+1;for(;i<t.length&&/[a-zA-Z0-9_]/.test(t[i]);)i++;let l=t.slice(s+1,i);r+=e.state.env.get(l)??"",s=i;continue}}if(n==="\\"&&s+1<t.length){r+=n+t[s+1],s+=2;continue}r+=n,s++}return r}function As(e,t){let r="",s=0;for(;s<t.length;){let n=t[s];if(n==="\\"&&s+1<t.length){let a=t[s+1];if(a==="$"||a==="`"||a==="\\"||a==='"'){r+=a,s+=2;continue}r+=n,s++;continue}if(n==="$"&&s+1<t.length){let a=t[s+1];if(a==="{"){let i=t.indexOf("}",s+2);if(i!==-1){let l=t.slice(s+2,i);r+=e.state.env.get(l)??"",s=i+1;continue}}else if(/[a-zA-Z_]/.test(a)){let i=s+1;for(;i<t.length&&/[a-zA-Z0-9_]/.test(t[i]);)i++;let l=t.slice(s+1,i);r+=e.state.env.get(l)??"",s=i;continue}}r+=n,s++}return r}async function Mn(e,t){let r="",s=0;for(;s<t.length;){let n=t[s];if(n==="'"){let a=t.indexOf("'",s+1);if(a!==-1){let i=t.slice(s+1,a);r+=K(i),s=a+1;continue}}if(n==='"'){let a=-1,i=s+1;for(;i<t.length;){if(t[i]==="\\"){i+=2;continue}if(t[i]==='"'){a=i;break}i++}if(a!==-1){let l=t.slice(s+1,a),o=await Ss(e,l);r+=K(o),s=a+1;continue}}if(n==="$"&&s+1<t.length&&t[s+1]==="("){let a=Tn(t,s+2);if(a!==-1){let i=t.slice(s+2,a),l=await We(e,i);r+=l,s=a+1;continue}}if(n==="`"){let a=t.indexOf("`",s+1);if(a!==-1){let i=t.slice(s+1,a),l=await We(e,i);r+=l,s=a+1;continue}}if(n==="$"&&s+1<t.length){let a=t[s+1];if(a==="{"){let i=t.indexOf("}",s+2);if(i!==-1){let l=t.slice(s+2,i);r+=e.state.env.get(l)??"",s=i+1;continue}}else if(/[a-zA-Z_]/.test(a)){let i=s+1;for(;i<t.length&&/[a-zA-Z0-9_]/.test(t[i]);)i++;let l=t.slice(s+1,i);r+=e.state.env.get(l)??"",s=i;continue}}if(n==="\\"&&s+1<t.length){r+=n+t[s+1],s+=2;continue}r+=n,s++}return r}async function Ss(e,t){let r="",s=0;for(;s<t.length;){let n=t[s];if(n==="\\"&&s+1<t.length){let a=t[s+1];if(a==="$"||a==="`"||a==="\\"||a==='"'){r+=a,s+=2;continue}r+=n,s++;continue}if(n==="$"&&s+1<t.length&&t[s+1]==="("){let a=Tn(t,s+2);if(a!==-1){let i=t.slice(s+2,a),l=await We(e,i);r+=l,s=a+1;continue}}if(n==="`"){let a=t.indexOf("`",s+1);if(a!==-1){let i=t.slice(s+1,a),l=await We(e,i);r+=l,s=a+1;continue}}if(n==="$"&&s+1<t.length){let a=t[s+1];if(a==="{"){let i=t.indexOf("}",s+2);if(i!==-1){let l=t.slice(s+2,i);r+=e.state.env.get(l)??"",s=i+1;continue}}else if(/[a-zA-Z_]/.test(a)){let i=s+1;for(;i<t.length&&/[a-zA-Z0-9_]/.test(t[i]);)i++;let l=t.slice(s+1,i);r+=e.state.env.get(l)??"",s=i;continue}}r+=n,s++}return r}function Vn(e,t){if(!t.startsWith("~"))return t;let r=e.state.env.get("HOME")!==void 0?e.state.env.get("HOME"):"/home/user";if(t==="~"||t.startsWith("~/"))return r+t.slice(1);let s=1;for(;s<t.length&&/[a-zA-Z0-9_-]/.test(t[s]);)s++;let n=t.slice(1,s),a=t.slice(s);return a!==""&&!a.startsWith("/")?t:n==="root"?`/root${a}`:t}async function bs(e,t,r,s){let n="";for(let a of t.parts)if(a.type==="Glob")n+=k(a.pattern,!0,e.state.shoptOptions.extglob);else if(a.type==="Literal")n+=k(a.value,!0,e.state.shoptOptions.extglob);else if(a.type==="SingleQuoted"||a.type==="Escaped")n+=I(a.value);else if(a.type==="DoubleQuoted"){let i=await r(e,a.parts);n+=I(i)}else if(a.type==="ParameterExpansion"){let i=await s(e,a);n+=k(i,!0,e.state.shoptOptions.extglob)}else{let i=await s(e,a);n+=I(i)}return n}async function qn(e,t,r,s){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0];if(n.parts.length!==1||n.parts[0].type!=="ParameterExpansion"||n.parts[0].operation?.type!=="PatternReplacement")return null;let a=n.parts[0],i=a.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!i)return null;let l=i[1],o=i[2]==="*",u=a.operation,c=P(e,l),f=c.map(([,E])=>E);if(c.length===0){let E=e.state.env.get(l);E!==void 0&&f.push(E)}if(f.length===0)return{values:[],quoted:!0};let p="";u.pattern&&(p=await bs(e,u.pattern,r,s));let d=u.replacement?await r(e,u.replacement.parts):"",g=p;u.anchor==="start"?g=`^${p}`:u.anchor==="end"&&(g=`${p}$`);let m=[];try{let E=O(g,u.all?"g":"");for(let A of f)m.push(E.replace(A,d))}catch{m.push(...f)}if(o){let E=N(e.state.env);return{values:[m.join(E)],quoted:!0}}return{values:m,quoted:!0}}async function Bn(e,t,r,s){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0];if(n.parts.length!==1||n.parts[0].type!=="ParameterExpansion"||n.parts[0].operation?.type!=="PatternRemoval")return null;let a=n.parts[0],i=a.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!i)return null;let l=i[1],o=i[2]==="*",u=a.operation,c=P(e,l),f=c.map(([,m])=>m);if(c.length===0){let m=e.state.env.get(l);m!==void 0&&f.push(m)}if(f.length===0)return{values:[],quoted:!0};let p="",d=e.state.shoptOptions.extglob;if(u.pattern)for(let m of u.pattern.parts)if(m.type==="Glob")p+=k(m.pattern,u.greedy,d);else if(m.type==="Literal")p+=k(m.value,u.greedy,d);else if(m.type==="SingleQuoted"||m.type==="Escaped")p+=I(m.value);else if(m.type==="DoubleQuoted"){let E=await r(e,m.parts);p+=I(E)}else if(m.type==="ParameterExpansion"){let E=await s(e,m);p+=k(E,u.greedy,d)}else{let E=await s(e,m);p+=I(E)}let g=[];for(let m of f)g.push(se(m,p,u.side,u.greedy));if(o){let m=N(e.state.env);return{values:[g.join(m)],quoted:!0}}return{values:g,quoted:!0}}async function Fn(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let r=t[0];if(r.parts.length!==1||r.parts[0].type!=="ParameterExpansion"||r.parts[0].operation?.type!=="DefaultValue"&&r.parts[0].operation?.type!=="UseAlternative"&&r.parts[0].operation?.type!=="AssignDefault")return null;let s=r.parts[0],n=s.operation,a=s.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/),i,l=!1;if(a){let o=a[1];l=a[2]==="*";let u=P(e,o),c=u.length>0||e.state.env.has(o),f=u.length===0||u.length===1&&u.every(([,d])=>d===""),p=n.checkEmpty??!1;if(n.type==="UseAlternative"?i=c&&!(p&&f):i=!c||p&&f,!i){if(u.length>0){let g=u.map(([,m])=>m);if(l){let m=N(e.state.env);return{values:[g.join(m)],quoted:!0}}return{values:g,quoted:!0}}let d=e.state.env.get(o);return d!==void 0?{values:[d],quoted:!0}:{values:[],quoted:!0}}}else{let o=s.parameter,u=await te(e,o),c=await D(e,o),f=c==="",p=n.checkEmpty??!1;if(n.type==="UseAlternative"?i=u&&!(p&&f):i=!u||p&&f,!i)return{values:[c],quoted:!0}}if(i&&n.word){let o=n.word.parts,u=null,c=!1;for(let f of o)if(f.type==="ParameterExpansion"&&!f.operation){let p=f.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(p){u=p[1],c=p[2]==="*";break}}if(u){let f=P(e,u);if(f.length>0){let d=f.map(([,g])=>g);if(c||l){let g=N(e.state.env);return{values:[d.join(g)],quoted:!0}}return{values:d,quoted:!0}}let p=e.state.env.get(u);return p!==void 0?{values:[p],quoted:!0}:{values:[],quoted:!0}}}return null}async function Qn(e,t,r,s,n){if(!r||t.length!==1||t[0].type!=="DoubleQuoted")return null;let a=t[0],i=-1,l="",o=!1,u=null;for(let m=0;m<a.parts.length;m++){let E=a.parts[m];if(E.type==="ParameterExpansion"&&(E.operation?.type==="PatternRemoval"||E.operation?.type==="PatternReplacement")){let A=E.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(A){i=m,l=A[1],o=A[2]==="*",u=E.operation;break}}}if(i===-1||i===0&&i===a.parts.length-1)return null;let c="";for(let m=0;m<i;m++)c+=await s(e,a.parts[m]);let f="";for(let m=i+1;m<a.parts.length;m++)f+=await s(e,a.parts[m]);let p=P(e,l),d=p.map(([,m])=>m);if(p.length===0){let m=e.state.env.get(l);if(m!==void 0)d=[m];else{if(o)return{values:[c+f],quoted:!0};let E=c+f;return{values:E?[E]:[],quoted:!0}}}if(u?.type==="PatternRemoval"){let m=u,E="",A=e.state.shoptOptions.extglob;if(m.pattern)for(let S of m.pattern.parts)if(S.type==="Glob")E+=k(S.pattern,m.greedy,A);else if(S.type==="Literal")E+=k(S.value,m.greedy,A);else if(S.type==="SingleQuoted"||S.type==="Escaped")E+=I(S.value);else if(S.type==="DoubleQuoted"){let y=await n(e,S.parts);E+=I(y)}else if(S.type==="ParameterExpansion"){let y=await s(e,S);E+=k(y,m.greedy,A)}else{let y=await s(e,S);E+=I(y)}d=d.map(S=>se(S,E,m.side,m.greedy))}else if(u?.type==="PatternReplacement"){let m=u,E="";if(m.pattern)for(let y of m.pattern.parts)if(y.type==="Glob")E+=k(y.pattern,!0,e.state.shoptOptions.extglob);else if(y.type==="Literal")E+=k(y.value,!0,e.state.shoptOptions.extglob);else if(y.type==="SingleQuoted"||y.type==="Escaped")E+=I(y.value);else if(y.type==="DoubleQuoted"){let b=await n(e,y.parts);E+=I(b)}else if(y.type==="ParameterExpansion"){let b=await s(e,y);E+=k(b,!0,e.state.shoptOptions.extglob)}else{let b=await s(e,y);E+=I(b)}let A=m.replacement?await n(e,m.replacement.parts):"",S=E;m.anchor==="start"?S=`^${E}`:m.anchor==="end"&&(S=`${E}$`);try{let y=O(S,m.all?"g":"");d=d.map(b=>y.replace(b,A))}catch{}}if(o){let m=N(e.state.env);return{values:[c+d.join(m)+f],quoted:!0}}return d.length===1?{values:[c+d[0]+f],quoted:!0}:{values:[c+d[0],...d.slice(1,-1),d[d.length-1]+f],quoted:!0}}async function zn(e,t,r,s){if(!r||t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0],a=-1,i="",l=!1;for(let d=0;d<n.parts.length;d++){let g=n.parts[d];if(g.type==="ParameterExpansion"&&!g.operation){let m=g.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(m){a=d,i=m[1],l=m[2]==="*";break}}}if(a===-1)return null;let o="";for(let d=0;d<a;d++)o+=await s(e,n.parts[d]);let u="";for(let d=a+1;d<n.parts.length;d++)u+=await s(e,n.parts[d]);let c=P(e,i),f=c.map(([,d])=>d);if(c.length===0){let d=e.state.env.get(i);if(d!==void 0)return{values:[o+d+u],quoted:!0};if(l)return{values:[o+u],quoted:!0};let g=o+u;return{values:g?[g]:[],quoted:!0}}if(l){let d=N(e.state.env);return{values:[o+f.join(d)+u],quoted:!0}}return f.length===1?{values:[o+f[0]+u],quoted:!0}:{values:[o+f[0],...f.slice(1,-1),f[f.length-1]+u],quoted:!0}}async function Zn(e,t,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0];if(s.parts.length!==1||s.parts[0].type!=="ParameterExpansion"||s.parts[0].operation?.type!=="Substring")return null;let n=s.parts[0],a=n.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!a)return null;let i=a[1],l=a[2]==="*",o=n.operation;if(e.state.associativeArrays?.has(i))throw new j(1,"",`bash: \${${i}[@]: 0: 3}: bad substitution
|
|
69
|
+
`);let u=o.offset?await r(e,o.offset.expression):0,c=o.length?await r(e,o.length.expression):void 0,f=P(e,i),p=0;if(u<0){if(f.length>0){let g=f[f.length-1][0],E=(typeof g=="number"?g:0)+1+u;if(E<0)return{values:[],quoted:!0};p=f.findIndex(([A])=>typeof A=="number"&&A>=E),p<0&&(p=f.length)}}else p=f.findIndex(([g])=>typeof g=="number"&&g>=u),p<0&&(p=f.length);let d;if(c!==void 0){if(c<0)throw new C(`${i}[@]: substring expression < 0`);d=f.slice(p,p+c).map(([,g])=>g)}else d=f.slice(p).map(([,g])=>g);if(d.length===0)return{values:[],quoted:!0};if(l){let g=N(e.state.env);return{values:[d.join(g)],quoted:!0}}return{values:d,quoted:!0}}function Gn(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let r=t[0];if(r.parts.length!==1||r.parts[0].type!=="ParameterExpansion"||r.parts[0].operation?.type!=="Transform")return null;let s=r.parts[0],n=s.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!n)return null;let a=n[1],i=n[2]==="*",l=s.operation,o=P(e,a);if(o.length===0){let f=e.state.env.get(a);if(f!==void 0){let p;switch(l.operator){case"a":p="";break;case"P":p=be(e,f);break;case"Q":p=le(f);break;default:p=f}return{values:[p],quoted:!0}}return i?{values:[""],quoted:!0}:{values:[],quoted:!0}}let u=ce(e,a),c;switch(l.operator){case"a":c=o.map(()=>u);break;case"P":c=o.map(([,f])=>be(e,f));break;case"Q":c=o.map(([,f])=>le(f));break;case"u":c=o.map(([,f])=>f.charAt(0).toUpperCase()+f.slice(1));break;case"U":c=o.map(([,f])=>f.toUpperCase());break;case"L":c=o.map(([,f])=>f.toLowerCase());break;default:c=o.map(([,f])=>f)}if(i){let f=N(e.state.env);return{values:[c.join(f)],quoted:!0}}return{values:c,quoted:!0}}function Un(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let r=t[0];if(r.parts.length!==1||r.parts[0].type!=="ParameterExpansion")return null;let s=r.parts[0];if(s.operation)return null;let n=s.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(@)\]$/);if(!n)return null;let a=n[1];if(L(e,a)){let o=Ae(e,a);if(o?.endsWith("[@]")||o?.endsWith("[*]"))return{values:[],quoted:!0}}let i=P(e,a);if(i.length>0)return{values:i.map(([,o])=>o),quoted:!0};let l=e.state.env.get(a);return l!==void 0?{values:[l],quoted:!0}:{values:[],quoted:!0}}function Hn(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let r=t[0];if(r.parts.length!==1||r.parts[0].type!=="ParameterExpansion"||r.parts[0].operation)return null;let n=r.parts[0].parameter;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n)||!L(e,n))return null;let a=Ae(e,n);if(!a)return null;let i=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(@)\]$/);if(!i)return null;let l=i[1],o=P(e,l);if(o.length>0)return{values:o.map(([,c])=>c),quoted:!0};let u=e.state.env.get(l);return u!==void 0?{values:[u],quoted:!0}:{values:[],quoted:!0}}async function jn(e,t,r,s,n){if(!r||t.length!==1||t[0].type!=="DoubleQuoted")return null;let a=t[0];if(a.parts.length!==1||a.parts[0].type!=="ParameterExpansion"||a.parts[0].operation?.type!=="Indirection")return null;let i=a.parts[0],l=i.operation,o=await D(e,i.parameter),u=o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!u){if(!l.innerOp&&(o==="@"||o==="*")){let g=Number.parseInt(e.state.env.get("#")||"0",10),m=[];for(let E=1;E<=g;E++)m.push(e.state.env.get(String(E))||"");return o==="*"?{values:[m.join(N(e.state.env))],quoted:!0}:{values:m,quoted:!0}}return null}let c=u[1],f=u[2]==="*",p=P(e,c);if(l.innerOp){if(l.innerOp.type==="Substring")return ws(e,p,c,f,l.innerOp);if(l.innerOp.type==="DefaultValue"||l.innerOp.type==="UseAlternative"||l.innerOp.type==="AssignDefault"||l.innerOp.type==="ErrorIfUnset")return Ns(e,p,c,f,l.innerOp,n);if(l.innerOp.type==="Transform"&&l.innerOp.operator==="a"){let m=ce(e,c),E=p.map(()=>m);return f?{values:[E.join(N(e.state.env))],quoted:!0}:{values:E,quoted:!0}}let g=[];for(let[,m]of p){let E={type:"ParameterExpansion",parameter:"_indirect_elem_",operation:l.innerOp},A=e.state.env.get("_indirect_elem_");e.state.env.set("_indirect_elem_",m);try{let S=await s(e,E,!0);g.push(S)}finally{A!==void 0?e.state.env.set("_indirect_elem_",A):e.state.env.delete("_indirect_elem_")}}return f?{values:[g.join(N(e.state.env))],quoted:!0}:{values:g,quoted:!0}}if(p.length>0){let g=p.map(([,m])=>m);return f?{values:[g.join(N(e.state.env))],quoted:!0}:{values:g,quoted:!0}}let d=e.state.env.get(c);return d!==void 0?{values:[d],quoted:!0}:{values:[],quoted:!0}}async function ws(e,t,r,s,n){let a=n.offset?await R(e,n.offset.expression):0,i=n.length?await R(e,n.length.expression):void 0,l=0;if(a<0){if(t.length>0){let c=t[t.length-1][0],p=(typeof c=="number"?c:0)+1+a;if(p<0)return{values:[],quoted:!0};if(l=t.findIndex(([d])=>typeof d=="number"&&d>=p),l<0)return{values:[],quoted:!0}}}else if(l=t.findIndex(([c])=>typeof c=="number"&&c>=a),l<0)return{values:[],quoted:!0};let o;if(i!==void 0){if(i<0)throw new C(`${r}[@]: substring expression < 0`);o=t.slice(l,l+i)}else o=t.slice(l);let u=o.map(([,c])=>c);return s?{values:[u.join(N(e.state.env))],quoted:!0}:{values:u,quoted:!0}}async function Ns(e,t,r,s,n,a){let i=n.checkEmpty??!1,l=t.map(([,c])=>c),o=t.length===0,u=t.length===0;if(n.type==="UseAlternative")return!u&&!(i&&o)&&n.word?{values:[await a(e,n.word.parts,!0)],quoted:!0}:{values:[],quoted:!0};if(n.type==="DefaultValue")return(u||i&&o)&&n.word?{values:[await a(e,n.word.parts,!0)],quoted:!0}:s?{values:[l.join(N(e.state.env))],quoted:!0}:{values:l,quoted:!0};if(n.type==="AssignDefault"){if((u||i&&o)&&n.word){let f=await a(e,n.word.parts,!0);return e.state.env.set(`${r}_0`,f),e.state.env.set(`${r}__length`,"1"),{values:[f],quoted:!0}}return s?{values:[l.join(N(e.state.env))],quoted:!0}:{values:l,quoted:!0}}return s?{values:[l.join(N(e.state.env))],quoted:!0}:{values:l,quoted:!0}}async function Kn(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="UseAlternative"&&t[0].operation?.type!=="DefaultValue")return null;let r=t[0],s=r.operation,n=s?.word;if(!n||n.parts.length!==1||n.parts[0].type!=="DoubleQuoted")return null;let a=n.parts[0];if(a.parts.length!==1||a.parts[0].type!=="ParameterExpansion"||a.parts[0].operation?.type!=="Indirection")return null;let i=a.parts[0],o=(await D(e,i.parameter)).match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!o)return null;let u=await te(e,r.parameter),c=await D(e,r.parameter)==="",f=s.checkEmpty??!1,p;if(s.type==="UseAlternative"?p=u&&!(f&&c):p=!u||f&&c,p){let d=o[1],g=o[2]==="*",m=P(e,d);if(m.length>0){let A=m.map(([,S])=>S);return g?{values:[A.join(N(e.state.env))],quoted:!0}:{values:A,quoted:!0}}let E=e.state.env.get(d);return E!==void 0?{values:[E],quoted:!0}:{values:[],quoted:!0}}return{values:[],quoted:!1}}async function Xn(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="Indirection")return null;let r=t[0],n=r.operation.innerOp;if(!n||n.type!=="UseAlternative"&&n.type!=="DefaultValue")return null;let a=n.word;if(!a||a.parts.length!==1||a.parts[0].type!=="DoubleQuoted")return null;let i=a.parts[0];if(i.parts.length!==1||i.parts[0].type!=="ParameterExpansion"||i.parts[0].operation?.type!=="Indirection")return null;let l=i.parts[0],u=(await D(e,l.parameter)).match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!u)return null;let c=await D(e,r.parameter),f=await te(e,r.parameter),p=c==="",d=n.checkEmpty??!1,g;if(n.type==="UseAlternative"?g=f&&!(d&&p):g=!f||d&&p,g){let m=u[1],E=u[2]==="*",A=P(e,m);if(A.length>0){let y=A.map(([,b])=>b);return E?{values:[y.join(N(e.state.env))],quoted:!0}:{values:y,quoted:!0}}let S=e.state.env.get(m);return S!==void 0?{values:[S],quoted:!0}:{values:[],quoted:!0}}return{values:[],quoted:!1}}function Jn(e){let t=Number.parseInt(e.state.env.get("#")||"0",10),r=[];for(let s=1;s<=t;s++)r.push(e.state.env.get(String(s))||"");return r}async function Yn(e,t,r,s){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0],a=-1,i=!1;for(let S=0;S<n.parts.length;S++){let y=n.parts[S];if(y.type==="ParameterExpansion"&&(y.parameter==="@"||y.parameter==="*")&&y.operation?.type==="Substring"){a=S,i=y.parameter==="*";break}}if(a===-1)return null;let o=n.parts[a].operation,u=o.offset?await r(e,o.offset.expression):0,c=o.length?await r(e,o.length.expression):void 0,f=Number.parseInt(e.state.env.get("#")||"0",10),p=[];for(let S=1;S<=f;S++)p.push(e.state.env.get(String(S))||"");let d=e.state.env.get("0")||"bash",g;if(u<=0){let S=[d,...p],y=S.length+u;if(y<0)g=[];else{let b=u<0?y:0;if(c!==void 0){let v=c<0?S.length+c:b+c;g=S.slice(b,Math.max(b,v))}else g=S.slice(b)}}else{let S=u-1;if(S>=p.length)g=[];else if(c!==void 0){let y=c<0?p.length+c:S+c;g=p.slice(S,Math.max(S,y))}else g=p.slice(S)}let m="";for(let S=0;S<a;S++)m+=await s(e,n.parts[S]);let E="";for(let S=a+1;S<n.parts.length;S++)E+=await s(e,n.parts[S]);if(g.length===0){let S=m+E;return{values:S?[S]:[],quoted:!0}}if(i){let S=N(e.state.env);return{values:[m+g.join(S)+E],quoted:!0}}return g.length===1?{values:[m+g[0]+E],quoted:!0}:{values:[m+g[0],...g.slice(1,-1),g[g.length-1]+E],quoted:!0}}async function er(e,t,r,s){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0],a=-1,i=!1;for(let A=0;A<n.parts.length;A++){let S=n.parts[A];if(S.type==="ParameterExpansion"&&(S.parameter==="@"||S.parameter==="*")&&S.operation?.type==="PatternReplacement"){a=A,i=S.parameter==="*";break}}if(a===-1)return null;let o=n.parts[a].operation,u=Jn(e),c="";for(let A=0;A<a;A++)c+=await r(e,n.parts[A]);let f="";for(let A=a+1;A<n.parts.length;A++)f+=await r(e,n.parts[A]);if(u.length===0){let A=c+f;return{values:A?[A]:[],quoted:!0}}let p="";if(o.pattern)for(let A of o.pattern.parts)if(A.type==="Glob")p+=k(A.pattern,!0,e.state.shoptOptions.extglob);else if(A.type==="Literal")p+=k(A.value,!0,e.state.shoptOptions.extglob);else if(A.type==="SingleQuoted"||A.type==="Escaped")p+=I(A.value);else if(A.type==="DoubleQuoted"){let S=await s(e,A.parts);p+=I(S)}else if(A.type==="ParameterExpansion"){let S=await r(e,A);p+=k(S,!0,e.state.shoptOptions.extglob)}else{let S=await r(e,A);p+=I(S)}let d=o.replacement?await s(e,o.replacement.parts):"",g=p;o.anchor==="start"?g=`^${p}`:o.anchor==="end"&&(g=`${p}$`);let m=[];try{let A=O(g,o.all?"g":"");for(let S of u)m.push(A.replace(S,d))}catch{m.push(...u)}if(i){let A=N(e.state.env);return{values:[c+m.join(A)+f],quoted:!0}}return m.length===1?{values:[c+m[0]+f],quoted:!0}:{values:[c+m[0],...m.slice(1,-1),m[m.length-1]+f],quoted:!0}}async function tr(e,t,r,s){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0],a=-1,i=!1;for(let E=0;E<n.parts.length;E++){let A=n.parts[E];if(A.type==="ParameterExpansion"&&(A.parameter==="@"||A.parameter==="*")&&A.operation?.type==="PatternRemoval"){a=E,i=A.parameter==="*";break}}if(a===-1)return null;let o=n.parts[a].operation,u=Jn(e),c="";for(let E=0;E<a;E++)c+=await r(e,n.parts[E]);let f="";for(let E=a+1;E<n.parts.length;E++)f+=await r(e,n.parts[E]);if(u.length===0){let E=c+f;return{values:E?[E]:[],quoted:!0}}let p="",d=e.state.shoptOptions.extglob;if(o.pattern)for(let E of o.pattern.parts)if(E.type==="Glob")p+=k(E.pattern,o.greedy,d);else if(E.type==="Literal")p+=k(E.value,o.greedy,d);else if(E.type==="SingleQuoted"||E.type==="Escaped")p+=I(E.value);else if(E.type==="DoubleQuoted"){let A=await s(e,E.parts);p+=I(A)}else if(E.type==="ParameterExpansion"){let A=await r(e,E);p+=k(A,o.greedy,d)}else{let A=await r(e,E);p+=I(A)}let g=[];for(let E of u)g.push(se(E,p,o.side,o.greedy));if(i){let E=N(e.state.env);return{values:[c+g.join(E)+f],quoted:!0}}return g.length===1?{values:[c+g[0]+f],quoted:!0}:{values:[c+g[0],...g.slice(1,-1),g[g.length-1]+f],quoted:!0}}async function nr(e,t,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0],n=-1,a=!1;for(let p=0;p<s.parts.length;p++){let d=s.parts[p];if(d.type==="ParameterExpansion"&&(d.parameter==="@"||d.parameter==="*")){n=p,a=d.parameter==="*";break}}if(n===-1)return null;let i=s.parts[n];if(i.type==="ParameterExpansion"&&i.operation)return null;let l=Number.parseInt(e.state.env.get("#")||"0",10),o="";for(let p=0;p<n;p++)o+=await r(e,s.parts[p]);let u="";for(let p=n+1;p<s.parts.length;p++)u+=await r(e,s.parts[p]);if(l===0){if(a)return{values:[o+u],quoted:!0};let p=o+u;return{values:p?[p]:[],quoted:!0}}let c=[];for(let p=1;p<=l;p++)c.push(e.state.env.get(String(p))||"");if(a){let p=N(e.state.env);return{values:[o+c.join(p)+u],quoted:!0}}return c.length===1?{values:[o+c[0]+u],quoted:!0}:{values:[o+c[0],...c.slice(1,-1),c[c.length-1]+u],quoted:!0}}function ks(e){return new oe(e.fs,e.state.cwd,e.state.env,{globstar:e.state.shoptOptions.globstar,nullglob:e.state.shoptOptions.nullglob,failglob:e.state.shoptOptions.failglob,dotglob:e.state.shoptOptions.dotglob,extglob:e.state.shoptOptions.extglob,globskipdots:e.state.shoptOptions.globskipdots,maxGlobOperations:e.limits.maxGlobOperations})}async function Te(e,t){if(e.state.options.noglob)return t;let r=ks(e),s=[];for(let n of t)if(ne(n,e.state.shoptOptions.extglob)){let a=await r.expand(n);if(a.length>0)s.push(...a);else{if(r.hasFailglob())throw new Pe(n);r.hasNullglob()||s.push(n)}}else s.push(n);return s}async function rr(e,t,r,s){let n=-1,a="",i=!1;for(let S=0;S<t.length;S++){let y=t[S];if(y.type==="ParameterExpansion"&&y.operation?.type==="PatternReplacement"){let b=y.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(b){n=S,a=b[1],i=b[2]==="*";break}}}if(n===-1)return null;let o=t[n].operation,u=P(e,a),c=u.map(([,S])=>S);if(u.length===0){let S=e.state.env.get(a);S!==void 0&&(c=[S])}if(c.length===0)return{values:[],quoted:!1};let f="";if(o.pattern)for(let S of o.pattern.parts)if(S.type==="Glob")f+=k(S.pattern,!0,e.state.shoptOptions.extglob);else if(S.type==="Literal")f+=k(S.value,!0,e.state.shoptOptions.extglob);else if(S.type==="SingleQuoted"||S.type==="Escaped")f+=I(S.value);else if(S.type==="DoubleQuoted"){let y=await r(e,S.parts);f+=I(y)}else if(S.type==="ParameterExpansion"){let y=await s(e,S);f+=k(y,!0,e.state.shoptOptions.extglob)}else{let y=await s(e,S);f+=I(y)}let p=o.replacement?await r(e,o.replacement.parts):"",d=f;o.anchor==="start"?d=`^${f}`:o.anchor==="end"&&(d=`${f}$`);let g=[];try{let S=O(d,o.all?"g":"");for(let y of c)g.push(S.replace(y,p))}catch{g.push(...c)}let m=W(e.state.env),E=V(e.state.env);if(i){let S=N(e.state.env),y=g.join(S);return E?{values:y?[y]:[],quoted:!1}:{values:x(y,m),quoted:!1}}if(E)return{values:g,quoted:!1};let A=[];for(let S of g)S===""?A.push(""):A.push(...x(S,m));return{values:A,quoted:!1}}async function sr(e,t,r,s){let n=-1,a="",i=!1;for(let A=0;A<t.length;A++){let S=t[A];if(S.type==="ParameterExpansion"&&S.operation?.type==="PatternRemoval"){let y=S.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(y){n=A,a=y[1],i=y[2]==="*";break}}}if(n===-1)return null;let o=t[n].operation,u=P(e,a),c=u.map(([,A])=>A);if(u.length===0){let A=e.state.env.get(a);A!==void 0&&(c=[A])}if(c.length===0)return{values:[],quoted:!1};let f="",p=e.state.shoptOptions.extglob;if(o.pattern)for(let A of o.pattern.parts)if(A.type==="Glob")f+=k(A.pattern,o.greedy,p);else if(A.type==="Literal")f+=k(A.value,o.greedy,p);else if(A.type==="SingleQuoted"||A.type==="Escaped")f+=I(A.value);else if(A.type==="DoubleQuoted"){let S=await r(e,A.parts);f+=I(S)}else if(A.type==="ParameterExpansion"){let S=await s(e,A);f+=k(S,o.greedy,p)}else{let S=await s(e,A);f+=I(S)}let d=[];for(let A of c)d.push(se(A,f,o.side,o.greedy));let g=W(e.state.env),m=V(e.state.env);if(i){let A=N(e.state.env),S=d.join(A);return m?{values:S?[S]:[],quoted:!1}:{values:x(S,g),quoted:!1}}if(m)return{values:d,quoted:!1};let E=[];for(let A of d)A===""?E.push(""):E.push(...x(A,g));return{values:E,quoted:!1}}async function ir(e,t,r,s){let n=-1,a=!1;for(let E=0;E<t.length;E++){let A=t[E];if(A.type==="ParameterExpansion"&&(A.parameter==="@"||A.parameter==="*")&&A.operation?.type==="PatternRemoval"){n=E,a=A.parameter==="*";break}}if(n===-1)return null;let l=t[n].operation,o=Number.parseInt(e.state.env.get("#")||"0",10),u=[];for(let E=1;E<=o;E++)u.push(e.state.env.get(String(E))||"");if(u.length===0)return{values:[],quoted:!1};let c="",f=e.state.shoptOptions.extglob;if(l.pattern)for(let E of l.pattern.parts)if(E.type==="Glob")c+=k(E.pattern,l.greedy,f);else if(E.type==="Literal")c+=k(E.value,l.greedy,f);else if(E.type==="SingleQuoted"||E.type==="Escaped")c+=I(E.value);else if(E.type==="DoubleQuoted"){let A=await r(e,E.parts);c+=I(A)}else if(E.type==="ParameterExpansion"){let A=await s(e,E);c+=k(A,l.greedy,f)}else{let A=await s(e,E);c+=I(A)}let p=[];for(let E of u)p.push(se(E,c,l.side,l.greedy));let d=W(e.state.env),g=V(e.state.env);if(a){let E=N(e.state.env),A=p.join(E);return g?{values:A?[A]:[],quoted:!1}:{values:x(A,d),quoted:!1}}if(g)return{values:p,quoted:!1};let m=[];for(let E of p)E===""?m.push(""):m.push(...x(E,d));return{values:m,quoted:!1}}async function ar(e,t,r,s){let n=-1,a=!1;for(let y=0;y<t.length;y++){let b=t[y];if(b.type==="ParameterExpansion"&&(b.parameter==="@"||b.parameter==="*")&&b.operation?.type==="Substring"){n=y,a=b.parameter==="*";break}}if(n===-1)return null;let l=t[n].operation,o=l.offset?await r(e,l.offset.expression):0,u=l.length?await r(e,l.length.expression):void 0,c=Number.parseInt(e.state.env.get("#")||"0",10),f=[];for(let y=1;y<=c;y++)f.push(e.state.env.get(String(y))||"");let p=e.state.env.get("0")||"bash",d;if(o<=0){let y=[p,...f],b=y.length+o;if(b<0)d=[];else{let v=o<0?b:0;if(u!==void 0){let Z=u<0?y.length+u:v+u;d=y.slice(v,Math.max(v,Z))}else d=y.slice(v)}}else{let y=o-1;if(y>=f.length)d=[];else if(u!==void 0){let b=u<0?f.length+u:y+u;d=f.slice(y,Math.max(y,b))}else d=f.slice(y)}let g="";for(let y=0;y<n;y++)g+=await s(e,t[y]);let m="";for(let y=n+1;y<t.length;y++)m+=await s(e,t[y]);let E=W(e.state.env),A=V(e.state.env);if(d.length===0){let y=g+m;return y?A?{values:[y],quoted:!1}:{values:x(y,E),quoted:!1}:{values:[],quoted:!1}}let S;if(a){let y=N(e.state.env),b=g+d.join(y)+m;A?S=b?[b]:[]:S=x(b,E)}else if(A)d.length===1?S=[g+d[0]+m]:S=[g+d[0],...d.slice(1,-1),d[d.length-1]+m];else{S=[];for(let y=0;y<d.length;y++){let b=d[y];if(y===0&&(b=g+b),y===d.length-1&&(b=b+m),b==="")S.push("");else{let v=x(b,E);S.push(...v)}}}return{values:await Te(e,S),quoted:!1}}async function or(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].parameter!=="@"&&t[0].parameter!=="*"||t[0].operation)return null;let r=t[0].parameter==="*",s=Number.parseInt(e.state.env.get("#")||"0",10);if(s===0)return{values:[],quoted:!1};let n=[];for(let u=1;u<=s;u++)n.push(e.state.env.get(String(u))||"");let a=W(e.state.env),i=V(e.state.env),l=Ce(e.state.env),o;if(r)if(i)o=n.filter(u=>u!=="");else{let u=N(e.state.env),c=n.join(u);o=x(c,a)}else if(i)o=n.filter(u=>u!=="");else if(l){o=[];for(let u of n){if(u==="")continue;let c=x(u,a);o.push(...c)}}else{o=[];for(let u of n)if(u==="")o.push("");else{let c=x(u,a);o.push(...c)}for(;o.length>0&&o[o.length-1]==="";)o.pop()}return{values:await Te(e,o),quoted:!1}}async function lr(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation)return null;let r=t[0].parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!r)return null;let s=r[1],n=r[2]==="*",a=P(e,s),i;if(a.length===0){let f=e.state.env.get(s);if(f!==void 0)i=[f];else return{values:[],quoted:!1}}else i=a.map(([,f])=>f);let l=W(e.state.env),o=V(e.state.env),u=Ce(e.state.env),c;if(n)if(o)c=i.filter(f=>f!=="");else{let f=N(e.state.env),p=i.join(f);c=x(p,l)}else if(o)c=i.filter(f=>f!=="");else if(u){c=[];for(let f of i){if(f==="")continue;let p=x(f,l);c.push(...p)}}else{c=[];for(let f of i)if(f==="")c.push("");else{let p=x(f,l);c.push(...p)}for(;c.length>0&&c[c.length-1]==="";)c.pop()}return{values:await Te(e,c),quoted:!1}}function cr(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="VarNamePrefix")return null;let r=t[0].operation,s=de(e,r.prefix);if(s.length===0)return{values:[],quoted:!1};let n=W(e.state.env),a=V(e.state.env),i;if(r.star)if(a)i=s;else{let l=N(e.state.env),o=s.join(l);i=x(o,n)}else if(a)i=s;else{i=[];for(let l of s){let o=x(l,n);i.push(...o)}}return{values:i,quoted:!1}}function ur(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="ArrayKeys")return null;let r=t[0].operation,n=P(e,r.array).map(([o])=>String(o));if(n.length===0)return{values:[],quoted:!1};let a=W(e.state.env),i=V(e.state.env),l;if(r.star)if(i)l=n;else{let o=N(e.state.env),u=n.join(o);l=x(u,a)}else if(i)l=n;else{l=[];for(let o of n){let u=x(o,a);l.push(...u)}}return{values:l,quoted:!1}}async function fr(e,t,r){let s=-1;for(let p=0;p<t.length;p++){let d=t[p];if(d.type==="ParameterExpansion"&&(d.parameter==="@"||d.parameter==="*")&&!d.operation){s=p;break}}if(s===-1||t.length<=1)return null;let n=Number.parseInt(e.state.env.get("#")||"0",10),a=[];for(let p=1;p<=n;p++)a.push(e.state.env.get(String(p))||"");let i="";for(let p=0;p<s;p++)i+=await r(e,t[p]);let l="";for(let p=s+1;p<t.length;p++)l+=await r(e,t[p]);let o=W(e.state.env),u=V(e.state.env),c=Ce(e.state.env);if(n===0){let p=i+l;return{values:p?[p]:[],quoted:!1}}let f;{let p=[];for(let d=0;d<a.length;d++){let g=a[d];d===0&&(g=i+g),d===a.length-1&&(g=g+l),p.push(g)}if(u)f=p.filter(d=>d!=="");else if(c){f=[];for(let d of p){if(d==="")continue;let g=x(d,o);f.push(...g)}}else{f=[];for(let d of p)if(d==="")f.push("");else{let g=x(d,o);f.push(...g)}for(;f.length>0&&f[f.length-1]==="";)f.pop()}}return f.length===0?{values:[],quoted:!1}:{values:await Te(e,f),quoted:!1}}async function dr(e,t,r){let s=t.parts,{hasQuoted:n,hasCommandSub:a,hasArrayVar:i,hasArrayAtExpansion:l,hasParamExpansion:o,hasVarNamePrefixExpansion:u,hasIndirection:c}=ye(s),p=r.hasBraceExpansion(s)?await r.expandWordWithBracesAsync(e,t):null;if(p&&p.length>1)return Ps(e,p,n);let d=await Rs(e,s,l,u,c,r);if(d!==null)return d;let g=await Ds(e,s,r);if(g!==null)return g;let m=await vs(e,s,r);if(m!==null)return m;let E=await $s(e,s,r.expandPart);if(E!==null)return hr(e,E);if((a||i||o)&&!V(e.state.env)){let S=W(e.state.env),y=r.buildIfsCharClassPattern(S),b=await r.smartWordSplit(e,s,S,y,r.expandPart);return hr(e,b)}let A=await r.expandWordAsync(e,t);return _s(e,t,s,A,n,r.expandWordForGlobbing)}async function Ps(e,t,r){let s=[];for(let n of t)if(!(!r&&n===""))if(!r&&!e.state.options.noglob&&ne(n,e.state.shoptOptions.extglob)){let a=await Me(e,n);s.push(...a)}else s.push(n);return{values:s,quoted:!1}}async function Rs(e,t,r,s,n,a){if(r){let i=Un(e,t);if(i!==null)return i}{let i=Hn(e,t);if(i!==null)return i}{let i=await Fn(e,t);if(i!==null)return i}{let i=await Qn(e,t,r,a.expandPart,a.expandWordPartsAsync);if(i!==null)return i}{let i=await zn(e,t,r,a.expandPart);if(i!==null)return i}{let i=await Zn(e,t,a.evaluateArithmetic);if(i!==null)return i}{let i=Gn(e,t);if(i!==null)return i}{let i=await qn(e,t,a.expandWordPartsAsync,a.expandPart);if(i!==null)return i}{let i=await Bn(e,t,a.expandWordPartsAsync,a.expandPart);if(i!==null)return i}if(s&&t.length===1&&t[0].type==="DoubleQuoted"){let i=Is(e,t);if(i!==null)return i}{let i=await jn(e,t,n,a.expandParameterAsync,a.expandWordPartsAsync);if(i!==null)return i}{let i=await Kn(e,t);if(i!==null)return i}{let i=await Xn(e,t);if(i!==null)return i}return null}function Is(e,t){let r=t[0];if(r.type!=="DoubleQuoted")return null;if(r.parts.length===1&&r.parts[0].type==="ParameterExpansion"&&r.parts[0].operation?.type==="VarNamePrefix"){let s=r.parts[0].operation,n=de(e,s.prefix);return s.star?{values:[n.join(N(e.state.env))],quoted:!0}:{values:n,quoted:!0}}if(r.parts.length===1&&r.parts[0].type==="ParameterExpansion"&&r.parts[0].operation?.type==="ArrayKeys"){let s=r.parts[0].operation,a=P(e,s.array).map(([i])=>String(i));return s.star?{values:[a.join(N(e.state.env))],quoted:!0}:{values:a,quoted:!0}}return null}async function Ds(e,t,r){{let s=await Yn(e,t,r.evaluateArithmetic,r.expandPart);if(s!==null)return s}{let s=await er(e,t,r.expandPart,r.expandWordPartsAsync);if(s!==null)return s}{let s=await tr(e,t,r.expandPart,r.expandWordPartsAsync);if(s!==null)return s}{let s=await nr(e,t,r.expandPart);if(s!==null)return s}return null}async function vs(e,t,r){{let s=await rr(e,t,r.expandWordPartsAsync,r.expandPart);if(s!==null)return s}{let s=await sr(e,t,r.expandWordPartsAsync,r.expandPart);if(s!==null)return s}{let s=await ir(e,t,r.expandWordPartsAsync,r.expandPart);if(s!==null)return s}{let s=await ar(e,t,r.evaluateArithmetic,r.expandPart);if(s!==null)return s}{let s=await or(e,t);if(s!==null)return s}{let s=await lr(e,t);if(s!==null)return s}{let s=cr(e,t);if(s!==null)return s}{let s=ur(e,t);if(s!==null)return s}{let s=await fr(e,t,r.expandPart);if(s!==null)return s}return null}function pr(e){if(e.type!=="DoubleQuoted")return null;for(let t=0;t<e.parts.length;t++){let r=e.parts[t];if(r.type!=="ParameterExpansion"||r.operation)continue;let s=r.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(s)return{type:"array",name:s[1],atIndex:t,isStar:s[2]==="*"};if(r.parameter==="@"||r.parameter==="*")return{type:"positional",atIndex:t,isStar:r.parameter==="*"}}return null}async function xs(e,t,r,s){let n="";for(let l=0;l<r.atIndex;l++)n+=await s(e,t.parts[l]);let a="";for(let l=r.atIndex+1;l<t.parts.length;l++)a+=await s(e,t.parts[l]);let i;if(r.type==="array"){if(i=P(e,r.name).map(([,o])=>o),i.length===0){let o=e.state.env.get(r.name);o!==void 0&&(i=[o])}}else{let l=Number.parseInt(e.state.env.get("#")||"0",10);i=[];for(let o=1;o<=l;o++)i.push(e.state.env.get(String(o))||"")}if(r.isStar){let l=N(e.state.env),o=i.join(l);return[n+o+a]}if(i.length===0){let l=n+a;return l?[l]:[]}return i.length===1?[n+i[0]+a]:[n+i[0],...i.slice(1,-1),i[i.length-1]+a]}async function $s(e,t,r){if(t.length<2)return null;let s=!1;for(let o of t)if(pr(o)){s=!0;break}if(!s)return null;let n=W(e.state.env),a=V(e.state.env),i=[];for(let o of t){let u=pr(o);if(u&&o.type==="DoubleQuoted"){let c=await xs(e,o,u,r);i.push(c)}else if(o.type==="DoubleQuoted"||o.type==="SingleQuoted"){let c=await r(e,o);i.push([c])}else if(o.type==="Literal")i.push([o.value]);else if(o.type==="ParameterExpansion"){let c=await r(e,o);if(a)i.push(c?[c]:[]);else{let f=x(c,n);i.push(f)}}else{let c=await r(e,o);if(a)i.push(c?[c]:[]);else{let f=x(c,n);i.push(f)}}}let l=[];for(let o of i)if(o.length!==0)if(l.length===0)l.push(...o);else{let u=l.length-1;l[u]=l[u]+o[0];for(let c=1;c<o.length;c++)l.push(o[c])}return l}async function hr(e,t){if(e.state.options.noglob)return{values:t,quoted:!1};let r=[];for(let s of t)if(ne(s,e.state.shoptOptions.extglob)){let n=await Me(e,s);r.push(...n)}else r.push(s);return{values:r,quoted:!1}}async function Me(e,t){let r=new oe(e.fs,e.state.cwd,e.state.env,{globstar:e.state.shoptOptions.globstar,nullglob:e.state.shoptOptions.nullglob,failglob:e.state.shoptOptions.failglob,dotglob:e.state.shoptOptions.dotglob,extglob:e.state.shoptOptions.extglob,globskipdots:e.state.shoptOptions.globskipdots,maxGlobOperations:e.limits.maxGlobOperations}),s=await r.expand(t);if(s.length>0)return s;if(r.hasFailglob())throw new Pe(t);return r.hasNullglob()?[]:[t]}async function _s(e,t,r,s,n,a){let i=r.some(l=>l.type==="Glob");if(!e.state.options.noglob&&i){let l=await a(e,t);if(ne(l,e.state.shoptOptions.extglob)){let u=await Me(e,l);if(u.length>0&&u[0]!==l)return{values:u,quoted:!1};if(u.length===0)return{values:[],quoted:!1}}let o=St(s);if(!V(e.state.env)){let u=W(e.state.env);return{values:x(o,u),quoted:!1}}return{values:[o],quoted:!1}}if(!n&&!e.state.options.noglob&&ne(s,e.state.shoptOptions.extglob)){let l=await a(e,t);if(ne(l,e.state.shoptOptions.extglob)){let o=await Me(e,l);if(o.length>0&&o[0]!==l)return{values:o,quoted:!1}}}if(s===""&&!n)return{values:[],quoted:!1};if(i&&!n){let l=St(s);if(!V(e.state.env)){let o=W(e.state.env);return{values:x(l,o),quoted:!1}}return{values:[l],quoted:!1}}return{values:[s],quoted:n}}async function gr(e,t){let r=t.operation;if(!r||r.type!=="DefaultValue"&&r.type!=="AssignDefault"&&r.type!=="UseAlternative")return null;let s=r.word;if(!s||s.parts.length===0)return null;let n=await te(e,t.parameter),i=await D(e,t.parameter,!1)==="",l=r.checkEmpty??!1,o;return r.type==="UseAlternative"?o=n&&!(l&&i):o=!n||l&&i,o?s.parts:null}function Cs(e){return e.type==="SingleQuoted"?!0:e.type==="DoubleQuoted"?e.parts.every(r=>r.type==="Literal"):!1}async function Os(e,t){if(t.type!=="ParameterExpansion")return null;let r=await gr(e,t);if(!r||r.length<=1)return null;let s=r.some(a=>Cs(a)),n=r.some(a=>a.type==="Literal"||a.type==="ParameterExpansion"||a.type==="CommandSubstitution"||a.type==="ArithmeticExpansion");return s&&n?r:null}function Ls(e){return e.type==="DoubleQuoted"||e.type==="SingleQuoted"||e.type==="Literal"?!1:e.type==="Glob"?dt(e.pattern):!(!(e.type==="ParameterExpansion"||e.type==="CommandSubstitution"||e.type==="ArithmeticExpansion")||e.type==="ParameterExpansion"&&mn(e))}async function yr(e,t,r,s,n){if(t.length===1&&t[0].type==="ParameterExpansion"){let p=t[0],d=await gr(e,p);if(d&&d.length>0&&d.length>1&&d.some(m=>m.type==="DoubleQuoted"||m.type==="SingleQuoted")&&d.some(m=>m.type==="Literal"||m.type==="ParameterExpansion"||m.type==="CommandSubstitution"||m.type==="ArithmeticExpansion"))return mr(e,d,r,s,n)}let a=[],i=!1;for(let p of t){let d=Ls(p),g=p.type==="DoubleQuoted"||p.type==="SingleQuoted",m=d?await Os(e,p):null,E=await n(e,p);a.push({value:E,isSplittable:d,isQuoted:g,mixedDefaultParts:m??void 0}),d&&(i=!0)}if(!i){let p=a.map(d=>d.value).join("");return p?[p]:[]}let l=[],o="",u=!1,c=!1,f=!1;for(let p of a)if(!p.isSplittable)c?p.isQuoted&&p.value===""?(o!==""&&l.push(o),l.push(""),u=!0,o="",c=!1,f=!0):p.value!==""?(o!==""&&l.push(o),o=p.value,c=!1,f=!1):(o+=p.value,f=!1):(o+=p.value,f=p.isQuoted&&p.value==="");else if(p.mixedDefaultParts){let d=await mr(e,p.mixedDefaultParts,r,s,n);if(d.length!==0)if(d.length===1)o+=d[0],u=!0;else{o+=d[0],l.push(o),u=!0;for(let g=1;g<d.length-1;g++)l.push(d[g]);o=d[d.length-1]}c=!1,f=!1}else{let{words:d,hadLeadingDelimiter:g,hadTrailingDelimiter:m}=Oe(p.value,r);if(f&&g&&o===""&&(l.push(""),u=!0),d.length===0)m&&(c=!0);else if(d.length===1)o+=d[0],u=!0,c=m;else{o+=d[0],l.push(o),u=!0;for(let E=1;E<d.length-1;E++)l.push(d[E]);o=d[d.length-1],c=m}f=!1}return o!==""?l.push(o):l.length===0&&u&&l.push(""),l}function Ws(e,t){return e.length>0&&t.includes(e[0])}async function mr(e,t,r,s,n){let a=[];for(let c of t){let p=!(c.type==="DoubleQuoted"||c.type==="SingleQuoted"),d=await n(e,c);a.push({value:d,isSplittable:p})}let i=[],l="",o=!1,u=!1;for(let c of a)if(!c.isSplittable)u&&c.value!==""?(l!==""&&i.push(l),l=c.value,u=!1):l+=c.value;else{Ws(c.value,r)&&l!==""&&(i.push(l),l="",o=!0);let{words:p,hadTrailingDelimiter:d}=Oe(c.value,r);if(p.length===0)d&&(u=!0);else if(p.length===1)l+=p[0],o=!0,u=d;else{l+=p[0],i.push(l),o=!0;for(let g=1;g<p.length-1;g++)i.push(p[g]);l=p[p.length-1],u=d}}return l!==""?i.push(l):i.length===0&&o&&i.push(""),i}function Er(e){switch(e.type){case"Literal":return e.value;case"SingleQuoted":return e.value;case"Escaped":return e.value;default:return null}}function Ar(e){switch(e.type){case"SingleQuoted":case"Escaped":case"DoubleQuoted":return!0;case"Literal":return e.value==="";default:return!1}}function we(e,t,r){if(e.length>t)throw new B(`${r}: string length limit exceeded (${t} bytes)`,"string_length")}async function X(e,t,r=!1){let s=[];for(let n of t)s.push(await U(e,n,r));return s.join("")}function Ts(e){return Ar(e)}function Al(e){if(e.parts.length===0)return!0;for(let t of e.parts)if(!Ts(t))return!1;return!0}function Ms(e,t,r=!1){let s=Er(t);if(s!==null)return s;switch(t.type){case"TildeExpansion":return r?t.user===null?"~":`~${t.user}`:t.user===null?e.state.env.get("HOME")??"/home/user":t.user==="root"?"/root":`~${t.user}`;case"Glob":return Nt(e,t.pattern);default:return null}}async function Pt(e,t){return Rt(e,t)}async function Sl(e,t){let r=[];for(let s of t.parts)if(s.type==="Escaped")r.push(`\\${s.value}`);else if(s.type==="SingleQuoted")r.push(s.value);else if(s.type==="DoubleQuoted"){let n=await X(e,s.parts);r.push(n)}else if(s.type==="TildeExpansion"){let n=await U(e,s);r.push(bt(n))}else r.push(await U(e,s));return r.join("")}async function bl(e,t){let r=[];for(let s of t.parts)if(s.type==="Escaped"){let n=s.value;"()|*?[]".includes(n)?r.push(`\\${n}`):r.push(n)}else if(s.type==="SingleQuoted")r.push(K(s.value));else if(s.type==="DoubleQuoted"){let n=await X(e,s.parts);r.push(K(n))}else r.push(await U(e,s));return r.join("")}async function Sr(e,t){let r=[];for(let s of t.parts)if(s.type==="SingleQuoted")r.push(K(s.value));else if(s.type==="Escaped"){let n=s.value;"*?[]\\()|".includes(n)?r.push(`\\${n}`):r.push(n)}else if(s.type==="DoubleQuoted"){let n=await X(e,s.parts);r.push(K(n))}else s.type==="Glob"?Wn(s.pattern)?r.push(await Mn(e,s.pattern)):r.push(Nt(e,s.pattern)):s.type==="Literal"?r.push(s.value):r.push(await U(e,s));return r.join("")}function qe(e){for(let t of e)if(t.type==="BraceExpansion"||t.type==="DoubleQuoted"&&qe(t.parts))return!0;return!1}var Vs=1e4,kt=1e5;async function br(e,t,r={count:0}){if(r.count>kt)return[[]];let s=[[]];for(let n of t)if(n.type==="BraceExpansion"){let a=[],i=!1,l="";for(let c of n.items)if(c.type==="Range"){let f=At(c.start,c.end,c.step,c.startStr,c.endStr);if(f.expanded)for(let p of f.expanded)r.count++,a.push(p);else{i=!0,l=f.literal;break}}else{let f=await br(e,c.word.parts,r);for(let p of f){r.count++;let d=[];for(let g of p)typeof g=="string"?d.push(g):d.push(await U(e,g));a.push(d.join(""))}}if(i){for(let c of s)r.count++,c.push(l);continue}if(s.length*a.length>Vs||r.count>kt)return s;let u=[];for(let c of s)for(let f of a){if(r.count++,r.count>kt)return u.length>0?u:s;u.push([...c,f])}s=u}else for(let a of s)r.count++,a.push(n);return s}async function wr(e,t){let r=t.parts;if(!qe(r))return[await Pt(e,t)];let s=await br(e,r),n=[];for(let a of s){let i=[];for(let l of a)typeof l=="string"?i.push(l):i.push(await U(e,l));n.push(Vn(e,i.join("")))}return n}function qs(){return{expandWordAsync:Rt,expandWordForGlobbing:Sr,expandWordWithBracesAsync:wr,expandWordPartsAsync:X,expandPart:U,expandParameterAsync:Ve,hasBraceExpansion:qe,evaluateArithmetic:R,buildIfsCharClassPattern:En,smartWordSplit:yr}}async function wl(e,t){return dr(e,t,qs())}function Bs(e){for(let t of e){if(t.type==="ParameterExpansion")return t.parameter;if(t.type==="Literal")return t.value}return""}function Fs(e,t){if(Number.parseInt(e.state.env.get("#")||"0",10)<2)return!1;function s(n){for(let a of n)if(a.type==="DoubleQuoted"){for(let i of a.parts)if(i.type==="ParameterExpansion"&&i.parameter==="@"&&!i.operation)return!0}return!1}return s(t.parts)}async function Nl(e,t){if(Fs(e,t))return{error:`bash: $@: ambiguous redirect
|
|
70
|
+
`};let r=t.parts,{hasQuoted:s}=ye(r);if(qe(r)&&(await wr(e,t)).length>1)return{error:`bash: ${r.map(d=>d.type==="Literal"?d.value:d.type==="BraceExpansion"?`{${d.items.map(m=>{if(m.type==="Range"){let E=m.step?`..${m.step}`:"";return`${m.startStr??m.start}..${m.endStr??m.end}${E}`}return m.word.parts.map(E=>E.type==="Literal"?E.value:"").join("")}).join(",")}}`:"").join("")}: ambiguous redirect
|
|
71
|
+
`};let n=await Rt(e,t),{hasParamExpansion:a,hasCommandSub:i}=ye(r);if((a||i)&&!s&&!V(e.state.env)){let f=W(e.state.env);if(x(n,f).length>1)return{error:`bash: $${Bs(r)}: ambiguous redirect
|
|
72
|
+
`}}if(s||e.state.options.noglob)return{target:n};let o=await Sr(e,t);if(!ne(o,e.state.shoptOptions.extglob))return{target:n};let u=new oe(e.fs,e.state.cwd,e.state.env,{globstar:e.state.shoptOptions.globstar,nullglob:e.state.shoptOptions.nullglob,failglob:e.state.shoptOptions.failglob,dotglob:e.state.shoptOptions.dotglob,extglob:e.state.shoptOptions.extglob,globskipdots:e.state.shoptOptions.globskipdots,maxGlobOperations:e.limits.maxGlobOperations}),c=await u.expand(o);return c.length===0?u.hasFailglob()?{error:`bash: no match: ${n}
|
|
73
73
|
`}:{target:n}:c.length===1?{target:c[0]}:{error:`bash: ${n}: ambiguous redirect
|
|
74
|
-
`}}async function
|
|
74
|
+
`}}async function Rt(e,t){let r=t.parts,s=r.length;if(s===1){let i=await U(e,r[0]);return we(i,e.limits.maxStringLength,"word expansion"),i}let n=[];for(let i=0;i<s;i++)n.push(await U(e,r[i]));let a=n.join("");return we(a,e.limits.maxStringLength,"word expansion"),a}async function U(e,t,r=!1){if(t.type==="ParameterExpansion")return Ve(e,t,r);let s=Ms(e,t,r);if(s!==null)return s;switch(t.type){case"DoubleQuoted":{let n=[];for(let a of t.parts)n.push(await U(e,a,!0));return n.join("")}case"CommandSubstitution":{let n=bn(t.body);if(n)try{let p=await Pt(e,n.target),d=p.startsWith("/")?p:`${e.state.cwd}/${p}`,g=await e.fs.readFile(d);e.state.lastExitCode=0,e.state.env.set("?","0");let m=g.replace(/\n+$/,"");return we(m,e.limits.maxStringLength,"command substitution"),m}catch(p){if(p instanceof B)throw p;return e.state.lastExitCode=1,e.state.env.set("?","1"),""}let a=e.substitutionDepth??0,i=e.limits.maxSubstitutionDepth;if(a>=i)throw new B(`Command substitution nesting limit exceeded (${i})`,"substitution_depth");let l=e.substitutionDepth;e.substitutionDepth=a+1;let o=e.state.bashPid;e.state.bashPid=e.state.nextVirtualPid++;let u=new Map(e.state.env),c=e.state.cwd,f=e.state.suppressVerbose;e.state.suppressVerbose=!0;try{let p=await e.executeScript(t.body),d=p.exitCode;e.state.env=u,e.state.cwd=c,e.state.suppressVerbose=f,e.state.lastExitCode=d,e.state.env.set("?",String(d)),p.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+p.stderr),e.state.bashPid=o,e.substitutionDepth=l;let g=p.stdout.replace(/\n+$/,"");return we(g,e.limits.maxStringLength,"command substitution"),g}catch(p){if(e.state.env=u,e.state.cwd=c,e.state.bashPid=o,e.substitutionDepth=l,e.state.suppressVerbose=f,p instanceof B)throw p;if(p instanceof j){e.state.lastExitCode=p.exitCode,e.state.env.set("?",String(p.exitCode)),p.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+p.stderr);let d=p.stdout.replace(/\n+$/,"");return we(d,e.limits.maxStringLength,"command substitution"),d}throw p}}case"ArithmeticExpansion":{let n=t.expression.originalText;if(n&&/\$[a-zA-Z_][a-zA-Z0-9_]*(?![{[(])/.test(n)){let i=await Sn(e,n),l=new M,o=T(l,i);return String(await R(e,o.expression,!0))}return String(await R(e,t.expression.expression,!0))}case"BraceExpansion":{let n=[];for(let a of t.items)if(a.type==="Range"){let i=At(a.start,a.end,a.step,a.startStr,a.endStr);if(i.expanded)n.push(...i.expanded);else return i.literal}else n.push(await Pt(e,a.word));return n.join(" ")}default:return""}}async function Ve(e,t,r=!1){let{parameter:s}=t,{operation:n}=t,a=s.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(a){let[,p,d]=a;if(e.state.associativeArrays?.has(p)||d.includes("$(")||d.includes("`")||d.includes("${")){let m=await Et(e,d);s=`${p}[${m}]`}}else if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s)&&L(e,s)){let p=fe(e,s);if(p&&p!==s){let d=p.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(d){let[,g,m]=d;if(e.state.associativeArrays?.has(g)||m.includes("$(")||m.includes("`")||m.includes("${")){let A=await Et(e,m);s=`${g}[${A}]`}}}}let i=n&&(n.type==="DefaultValue"||n.type==="AssignDefault"||n.type==="UseAlternative"||n.type==="ErrorIfUnset"),l=await D(e,s,!i);if(!n)return l;let o=!await te(e,s),{isEmpty:u,effectiveValue:c}=Ln(e,s,l,r),f={value:l,isUnset:o,isEmpty:u,effectiveValue:c,inDoubleQuotes:r};switch(n.type){case"DefaultValue":return wn(e,n,f,X);case"AssignDefault":return Nn(e,s,n,f,X);case"ErrorIfUnset":return kn(e,s,n,f,X);case"UseAlternative":return Pn(e,n,f,X);case"PatternRemoval":return Rn(e,l,n,X,U);case"PatternReplacement":return In(e,l,n,X,U);case"Length":return Dn(e,s,l);case"LengthSliceError":throw new re(s);case"BadSubstitution":throw new re(n.text);case"Substring":return vn(e,s,l,n);case"CaseModification":return xn(e,l,n,X,Ve);case"Transform":return $n(e,s,l,o,n);case"Indirection":return _n(e,s,l,o,n,Ve,r);case"ArrayKeys":return Cn(e,n);case"VarNamePrefix":return On(e,n);default:return l}}export{xi as a,$i as b,pe as c,z as d,T as e,M as f,di as g,mt as h,Ci as i,gt as j,Oi as k,yn as l,W as m,Wi as n,Ti as o,L as p,Vi as q,qi as r,Bi as s,Fi as t,ls as u,fe as v,Ae as w,Qi as x,P as y,Se as z,D as A,K as B,bt as C,ha as D,wt as E,da as F,ma as G,ga as H,Al as I,Pt as J,Sl as K,bl as L,wl as M,Fs as N,Nl as O,R as P};
|