just-bash 2.7.0 → 2.7.1

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.
Files changed (165) hide show
  1. package/dist/bin/chunks/alias-MGDOL4KG.js +7 -0
  2. package/dist/bin/chunks/awk2-ASLLINAN.js +21 -0
  3. package/dist/bin/{shell/chunks/base64-O7TCK5TL.js → chunks/base64-43KPK6TL.js} +1 -1
  4. package/dist/bin/chunks/bash-OAUBNRSG.js +6 -0
  5. package/dist/bin/{shell/chunks/cat-AJXZOSPN.js → chunks/cat-HNXE2ES2.js} +1 -1
  6. package/dist/bin/chunks/chunk-4PRVMER6.js +2 -0
  7. package/dist/bin/chunks/chunk-C6FK2JV3.js +74 -0
  8. package/dist/bin/chunks/chunk-GZHFXDDO.js +10 -0
  9. package/dist/bin/chunks/chunk-JBABAK44.js +4 -0
  10. package/dist/bin/chunks/chunk-YNACG4DZ.js +6 -0
  11. package/dist/bin/chunks/{column-TSFEMTG6.js → column-HQ4AK5DM.js} +1 -1
  12. package/dist/bin/chunks/{cp-XXWRVG2D.js → cp-VFXCUKXO.js} +1 -1
  13. package/dist/bin/chunks/{curl-TH7YRBSA.js → curl-7IUASLUJ.js} +1 -1
  14. package/dist/bin/chunks/{diff-GI3QVUGD.js → diff-ZGXLP3DN.js} +1 -1
  15. package/dist/bin/chunks/{du-XQPYLN3H.js → du-PECPOFQT.js} +1 -1
  16. package/dist/bin/chunks/env-W6IMQ43Y.js +9 -0
  17. package/dist/bin/chunks/{expansion-BOR3ELLC.js → expansion-IEMZ6T22.js} +1 -1
  18. package/dist/bin/{shell/chunks/gzip-YXK3WZQL.js → chunks/gzip-5ILPB46W.js} +1 -1
  19. package/dist/bin/chunks/history-56DL6SXU.js +3 -0
  20. package/dist/bin/{shell/chunks/jq-RGZHJNXC.js → chunks/jq-M2WXBRXF.js} +1 -1
  21. package/dist/bin/chunks/{ls-BEHQBUMC.js → ls-5LN47VHU.js} +1 -1
  22. package/dist/bin/chunks/{mkdir-XJABRAUN.js → mkdir-XMSNS6S5.js} +1 -1
  23. package/dist/bin/chunks/{mv-3ATZ2ABL.js → mv-P4KHB27X.js} +1 -1
  24. package/dist/bin/chunks/{paste-FT6WBQZG.js → paste-UCH462KK.js} +1 -1
  25. package/dist/bin/{shell/chunks/printf-YPXD4CRE.js → chunks/printf-XPBSFXJE.js} +1 -1
  26. package/dist/bin/{shell/chunks/python3-JGT65AEB.js → chunks/python3-ZWX5SFJ3.js} +5 -5
  27. package/dist/bin/{shell/chunks/rm-2PKAWTSQ.js → chunks/rm-S7ASVG34.js} +1 -1
  28. package/dist/bin/chunks/{rmdir-GOODLY5W.js → rmdir-OEMA5ZTD.js} +1 -1
  29. package/dist/bin/chunks/{stat-UEQ7KMY5.js → stat-ZZVPXHLF.js} +1 -1
  30. package/dist/bin/{shell/chunks/tee-ZFIT2GTM.js → chunks/tee-XSKPK43X.js} +1 -1
  31. package/dist/bin/chunks/time-F4NVQOJH.js +14 -0
  32. package/dist/bin/chunks/{tr-MBLEXZBI.js → tr-FMT6JWLE.js} +1 -1
  33. package/dist/bin/chunks/{tree-DQBEJH47.js → tree-WC3AXFHC.js} +1 -1
  34. package/dist/bin/chunks/{uniq-IXHB2FVS.js → uniq-NNXAFO6D.js} +1 -1
  35. package/dist/bin/{shell/chunks/wc-SAOHEZYP.js → chunks/wc-CZ2TD6T6.js} +1 -1
  36. package/dist/bin/{shell/chunks/which-FCDFBOMN.js → chunks/which-5QEJAXNR.js} +1 -1
  37. package/dist/bin/chunks/xan-OPVCJ3ZA.js +140 -0
  38. package/dist/bin/chunks/{xan-view-6Z6TWXMY.js → xan-view-5SZBYPLG.js} +1 -1
  39. package/dist/bin/chunks/{yq-PFV4T2PV.js → yq-JU6VN4X4.js} +1 -1
  40. package/dist/bin/just-bash.js +251 -251
  41. package/dist/bin/shell/chunks/alias-MGDOL4KG.js +7 -0
  42. package/dist/bin/shell/chunks/awk2-ASLLINAN.js +21 -0
  43. package/dist/bin/{chunks/base64-O7TCK5TL.js → shell/chunks/base64-43KPK6TL.js} +1 -1
  44. package/dist/bin/shell/chunks/bash-OAUBNRSG.js +6 -0
  45. package/dist/bin/{chunks/cat-AJXZOSPN.js → shell/chunks/cat-HNXE2ES2.js} +1 -1
  46. package/dist/bin/shell/chunks/chunk-4PRVMER6.js +2 -0
  47. package/dist/bin/shell/chunks/chunk-C6FK2JV3.js +74 -0
  48. package/dist/bin/shell/chunks/chunk-GZHFXDDO.js +10 -0
  49. package/dist/bin/shell/chunks/chunk-JBABAK44.js +4 -0
  50. package/dist/bin/shell/chunks/chunk-YNACG4DZ.js +6 -0
  51. package/dist/bin/shell/chunks/{column-TSFEMTG6.js → column-HQ4AK5DM.js} +1 -1
  52. package/dist/bin/shell/chunks/{cp-XXWRVG2D.js → cp-VFXCUKXO.js} +1 -1
  53. package/dist/bin/shell/chunks/{curl-TH7YRBSA.js → curl-7IUASLUJ.js} +1 -1
  54. package/dist/bin/shell/chunks/{diff-GI3QVUGD.js → diff-ZGXLP3DN.js} +1 -1
  55. package/dist/bin/shell/chunks/{du-XQPYLN3H.js → du-PECPOFQT.js} +1 -1
  56. package/dist/bin/shell/chunks/env-W6IMQ43Y.js +9 -0
  57. package/dist/bin/shell/chunks/{expansion-BOR3ELLC.js → expansion-IEMZ6T22.js} +1 -1
  58. package/dist/bin/{chunks/gzip-YXK3WZQL.js → shell/chunks/gzip-5ILPB46W.js} +1 -1
  59. package/dist/bin/shell/chunks/history-56DL6SXU.js +3 -0
  60. package/dist/bin/{chunks/jq-RGZHJNXC.js → shell/chunks/jq-M2WXBRXF.js} +1 -1
  61. package/dist/bin/shell/chunks/{ls-BEHQBUMC.js → ls-5LN47VHU.js} +1 -1
  62. package/dist/bin/shell/chunks/{mkdir-XJABRAUN.js → mkdir-XMSNS6S5.js} +1 -1
  63. package/dist/bin/shell/chunks/{mv-3ATZ2ABL.js → mv-P4KHB27X.js} +1 -1
  64. package/dist/bin/shell/chunks/{paste-FT6WBQZG.js → paste-UCH462KK.js} +1 -1
  65. package/dist/bin/{chunks/printf-YPXD4CRE.js → shell/chunks/printf-XPBSFXJE.js} +1 -1
  66. package/dist/bin/{chunks/python3-JGT65AEB.js → shell/chunks/python3-ZWX5SFJ3.js} +5 -5
  67. package/dist/bin/{chunks/rm-2PKAWTSQ.js → shell/chunks/rm-S7ASVG34.js} +1 -1
  68. package/dist/bin/shell/chunks/{rmdir-GOODLY5W.js → rmdir-OEMA5ZTD.js} +1 -1
  69. package/dist/bin/shell/chunks/{stat-UEQ7KMY5.js → stat-ZZVPXHLF.js} +1 -1
  70. package/dist/bin/{chunks/tee-ZFIT2GTM.js → shell/chunks/tee-XSKPK43X.js} +1 -1
  71. package/dist/bin/shell/chunks/time-F4NVQOJH.js +14 -0
  72. package/dist/bin/shell/chunks/{tr-MBLEXZBI.js → tr-FMT6JWLE.js} +1 -1
  73. package/dist/bin/shell/chunks/{tree-DQBEJH47.js → tree-WC3AXFHC.js} +1 -1
  74. package/dist/bin/shell/chunks/{uniq-IXHB2FVS.js → uniq-NNXAFO6D.js} +1 -1
  75. package/dist/bin/{chunks/wc-SAOHEZYP.js → shell/chunks/wc-CZ2TD6T6.js} +1 -1
  76. package/dist/bin/{chunks/which-FCDFBOMN.js → shell/chunks/which-5QEJAXNR.js} +1 -1
  77. package/dist/bin/shell/chunks/xan-OPVCJ3ZA.js +140 -0
  78. package/dist/bin/shell/chunks/{xan-view-6Z6TWXMY.js → xan-view-5SZBYPLG.js} +1 -1
  79. package/dist/bin/shell/chunks/{yq-PFV4T2PV.js → yq-JU6VN4X4.js} +1 -1
  80. package/dist/bin/shell/shell.js +226 -226
  81. package/dist/bundle/browser.js +623 -623
  82. package/dist/bundle/chunks/alias-YGOORMWI.js +6 -0
  83. package/dist/bundle/chunks/awk2-5K7HVGCQ.js +20 -0
  84. package/dist/bundle/chunks/{base64-3BME25ON.js → base64-2JFR3HGT.js} +1 -1
  85. package/dist/bundle/chunks/bash-BYWM5OPC.js +5 -0
  86. package/dist/bundle/chunks/{cat-MV4K6AUA.js → cat-GPKR7D6K.js} +1 -1
  87. package/dist/bundle/chunks/chunk-76ZRJPDK.js +73 -0
  88. package/dist/bundle/chunks/chunk-F55TLFGB.js +9 -0
  89. package/dist/bundle/chunks/chunk-HWKDQ44K.js +3 -0
  90. package/dist/bundle/chunks/chunk-IEPFPINK.js +5 -0
  91. package/dist/bundle/chunks/chunk-OJDRYQWQ.js +1 -0
  92. package/dist/bundle/chunks/{column-XPDNNO5Y.js → column-R6OLMEUA.js} +1 -1
  93. package/dist/bundle/chunks/{cp-PBJT3GBF.js → cp-NJSENVKC.js} +1 -1
  94. package/dist/bundle/chunks/{curl-XLP4VABU.js → curl-QDCXHQMX.js} +1 -1
  95. package/dist/bundle/chunks/{diff-ZLJYSBRK.js → diff-ELUS3RW7.js} +1 -1
  96. package/dist/bundle/chunks/{du-NQXEC3EF.js → du-T4JUAAB2.js} +1 -1
  97. package/dist/bundle/chunks/env-M3AXY56V.js +8 -0
  98. package/dist/bundle/chunks/{expansion-RIGCFEMA.js → expansion-DXWR3WZB.js} +1 -1
  99. package/dist/bundle/chunks/{gzip-L3NDJG3F.js → gzip-4P4KGYT5.js} +1 -1
  100. package/dist/bundle/chunks/history-TMBGOQO6.js +2 -0
  101. package/dist/bundle/chunks/{jq-RLRYRPOJ.js → jq-KF5D2PYR.js} +1 -1
  102. package/dist/bundle/chunks/{ls-5W3NU5OJ.js → ls-PUJHEPXS.js} +1 -1
  103. package/dist/bundle/chunks/{mkdir-7UKY4B3B.js → mkdir-SF2UE4KB.js} +1 -1
  104. package/dist/bundle/chunks/{mv-FXHEKRTB.js → mv-JPBZPM4O.js} +1 -1
  105. package/dist/bundle/chunks/{paste-QTGVEPH5.js → paste-QAP6Y75J.js} +1 -1
  106. package/dist/bundle/chunks/{printf-66XGXFCD.js → printf-OAPYPRGV.js} +1 -1
  107. package/dist/bundle/chunks/{python3-3OP7EKER.js → python3-SKZGHYDO.js} +5 -5
  108. package/dist/bundle/chunks/{rm-I2SRVF7H.js → rm-MJFRIDNT.js} +1 -1
  109. package/dist/bundle/chunks/{rmdir-XFQE4ZYV.js → rmdir-DU6C7ZEO.js} +1 -1
  110. package/dist/bundle/chunks/{stat-IVQBBOKN.js → stat-IOLJTP7U.js} +1 -1
  111. package/dist/bundle/chunks/{tee-2QU4NRSJ.js → tee-4KHTWVWB.js} +1 -1
  112. package/dist/bundle/chunks/time-EGF4KTWV.js +13 -0
  113. package/dist/bundle/chunks/{tr-EDGW5FG6.js → tr-P43NRVKL.js} +1 -1
  114. package/dist/bundle/chunks/{tree-MEM64BW3.js → tree-UFVZH4SS.js} +1 -1
  115. package/dist/bundle/chunks/{uniq-47QVBRNC.js → uniq-XBP4SJA3.js} +1 -1
  116. package/dist/bundle/chunks/{wc-HE5XARI4.js → wc-VDPK3LVS.js} +1 -1
  117. package/dist/bundle/chunks/{which-UBLRBDHN.js → which-GF77XMJD.js} +1 -1
  118. package/dist/bundle/chunks/xan-RW5GSH6C.js +139 -0
  119. package/dist/bundle/chunks/{xan-view-DMFUMZG7.js → xan-view-ECQUO7AJ.js} +1 -1
  120. package/dist/bundle/chunks/{yq-L665QPQU.js → yq-EMWRPC7R.js} +1 -1
  121. package/dist/bundle/index.js +253 -253
  122. package/dist/commands/query-engine/evaluator.d.ts +2 -2
  123. package/dist/commands/query-engine/safe-object.d.ts +49 -0
  124. package/dist/commands/query-engine/value-operations.d.ts +1 -0
  125. package/dist/commands/xan/aggregation.d.ts +1 -1
  126. package/dist/commands/xan/csv.d.ts +16 -0
  127. package/dist/interpreter/alias-expansion.d.ts +1 -1
  128. package/dist/interpreter/helpers/ifs.d.ts +4 -4
  129. package/dist/interpreter/simple-command-assignments.d.ts +1 -1
  130. package/dist/interpreter/types.d.ts +2 -2
  131. package/dist/types.d.ts +2 -2
  132. package/package.json +1 -1
  133. package/dist/bin/chunks/alias-EGIS5LUE.js +0 -7
  134. package/dist/bin/chunks/awk2-GFEJOWML.js +0 -21
  135. package/dist/bin/chunks/bash-PGDTHIM2.js +0 -6
  136. package/dist/bin/chunks/chunk-FSAGDARS.js +0 -74
  137. package/dist/bin/chunks/chunk-KD3EODLB.js +0 -6
  138. package/dist/bin/chunks/chunk-TA7RUHGQ.js +0 -4
  139. package/dist/bin/chunks/chunk-UUQYHLBO.js +0 -10
  140. package/dist/bin/chunks/env-7A4MH7BJ.js +0 -9
  141. package/dist/bin/chunks/history-G5C2J2OY.js +0 -3
  142. package/dist/bin/chunks/time-37F5EBPK.js +0 -14
  143. package/dist/bin/chunks/xan-5HNHTFMB.js +0 -140
  144. package/dist/bin/shell/chunks/alias-EGIS5LUE.js +0 -7
  145. package/dist/bin/shell/chunks/awk2-GFEJOWML.js +0 -21
  146. package/dist/bin/shell/chunks/bash-PGDTHIM2.js +0 -6
  147. package/dist/bin/shell/chunks/chunk-FSAGDARS.js +0 -74
  148. package/dist/bin/shell/chunks/chunk-KD3EODLB.js +0 -6
  149. package/dist/bin/shell/chunks/chunk-TA7RUHGQ.js +0 -4
  150. package/dist/bin/shell/chunks/chunk-UUQYHLBO.js +0 -10
  151. package/dist/bin/shell/chunks/env-7A4MH7BJ.js +0 -9
  152. package/dist/bin/shell/chunks/history-G5C2J2OY.js +0 -3
  153. package/dist/bin/shell/chunks/time-37F5EBPK.js +0 -14
  154. package/dist/bin/shell/chunks/xan-5HNHTFMB.js +0 -140
  155. package/dist/bundle/chunks/alias-ATFBB6D2.js +0 -6
  156. package/dist/bundle/chunks/awk2-6FBZTP57.js +0 -20
  157. package/dist/bundle/chunks/bash-OLRNM52U.js +0 -5
  158. package/dist/bundle/chunks/chunk-3AWP5CWK.js +0 -73
  159. package/dist/bundle/chunks/chunk-A263W2RD.js +0 -9
  160. package/dist/bundle/chunks/chunk-CZPA5RBA.js +0 -5
  161. package/dist/bundle/chunks/chunk-ZVV5VXYZ.js +0 -3
  162. package/dist/bundle/chunks/env-2UI6XINU.js +0 -8
  163. package/dist/bundle/chunks/history-MQDK2OPD.js +0 -2
  164. package/dist/bundle/chunks/time-UWXBG6CS.js +0 -13
  165. package/dist/bundle/chunks/xan-A6VPI4HJ.js +0 -139
@@ -14,7 +14,7 @@ export interface QueryExecutionLimits {
14
14
  export interface EvalContext {
15
15
  vars: Map<string, QueryValue>;
16
16
  limits: Required<Pick<QueryExecutionLimits, "maxIterations">> & QueryExecutionLimits;
17
- env?: Record<string, string | undefined>;
17
+ env?: Map<string, string>;
18
18
  /** Original document root for parent/root navigation */
19
19
  root?: QueryValue;
20
20
  /** Current path from root for parent navigation */
@@ -28,6 +28,6 @@ export interface EvalContext {
28
28
  }
29
29
  export interface EvaluateOptions {
30
30
  limits?: QueryExecutionLimits;
31
- env?: Record<string, string | undefined>;
31
+ env?: Map<string, string>;
32
32
  }
33
33
  export declare function evaluate(value: QueryValue, ast: AstNode, ctxOrOptions?: EvalContext | EvaluateOptions): QueryValue[];
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Safe Object Utilities
3
+ *
4
+ * Defense-in-depth against JavaScript prototype pollution attacks.
5
+ * These utilities prevent malicious JSON from accessing or modifying
6
+ * the JavaScript prototype chain via keys like "__proto__", "constructor", etc.
7
+ */
8
+ /**
9
+ * Check if a key is safe to use for object property access/assignment.
10
+ * Returns true if the key is safe, false if it could cause prototype pollution.
11
+ */
12
+ export declare function isSafeKey(key: string): boolean;
13
+ /**
14
+ * Check if a key is safe using the extended dangerous keys list.
15
+ * More paranoid version that blocks additional Object.prototype methods.
16
+ */
17
+ export declare function isSafeKeyStrict(key: string): boolean;
18
+ /**
19
+ * Safely get a property from an object using hasOwnProperty check.
20
+ * Returns undefined if the key is dangerous or doesn't exist as own property.
21
+ */
22
+ export declare function safeGet<T>(obj: Record<string, T>, key: string): T | undefined;
23
+ /**
24
+ * Safely set a property on an object.
25
+ * Silently ignores dangerous keys to prevent prototype pollution.
26
+ */
27
+ export declare function safeSet<T>(obj: Record<string, T>, key: string, value: T): void;
28
+ /**
29
+ * Safely delete a property from an object.
30
+ * Ignores dangerous keys.
31
+ */
32
+ export declare function safeDelete<T>(obj: Record<string, T>, key: string): void;
33
+ /**
34
+ * Create a safe object from entries, filtering out dangerous keys.
35
+ */
36
+ export declare function safeFromEntries<T>(entries: Iterable<[string, T]>): Record<string, T>;
37
+ /**
38
+ * Safely spread/assign properties from source to target.
39
+ * Only copies own properties and filters dangerous keys.
40
+ */
41
+ export declare function safeAssign<T>(target: Record<string, T>, source: Record<string, T>): Record<string, T>;
42
+ /**
43
+ * Create a shallow copy of an object, filtering dangerous keys.
44
+ */
45
+ export declare function safeCopy<T extends Record<string, unknown>>(obj: T): T;
46
+ /**
47
+ * Check if object has own property safely (not inherited from prototype).
48
+ */
49
+ export declare function safeHasOwn(obj: object, key: string): boolean;
@@ -21,6 +21,7 @@ export declare function compare(a: QueryValue, b: QueryValue): number;
21
21
  /**
22
22
  * Deep merge two objects.
23
23
  * Values from b override values from a, except nested objects are merged recursively.
24
+ * Filters out dangerous keys (__proto__, constructor, prototype) to prevent prototype pollution.
24
25
  */
25
26
  export declare function deepMerge(a: Record<string, unknown>, b: Record<string, unknown>): Record<string, unknown>;
26
27
  /**
@@ -2,7 +2,7 @@
2
2
  * Aggregation functions for xan command
3
3
  */
4
4
  import { type EvaluateOptions } from "../query-engine/index.js";
5
- import type { CsvData, CsvRow } from "./csv.js";
5
+ import { type CsvData, type CsvRow } from "./csv.js";
6
6
  /** Aggregation specification from parsed expression */
7
7
  export interface AggSpec {
8
8
  func: string;
@@ -6,6 +6,22 @@ export interface CsvRow {
6
6
  [key: string]: string | number | boolean | null;
7
7
  }
8
8
  export type CsvData = CsvRow[];
9
+ /**
10
+ * Create a null-prototype CsvRow to prevent prototype pollution.
11
+ * User-controlled CSV column names could match dangerous keys like
12
+ * __proto__, constructor, or prototype. Using a null-prototype object
13
+ * ensures these don't access the prototype chain.
14
+ */
15
+ export declare function createSafeRow(): CsvRow;
16
+ /**
17
+ * Set a property on a CsvRow.
18
+ * Since CsvRow uses null-prototype, this is safe from prototype pollution.
19
+ */
20
+ export declare function safeSetRow(row: CsvRow, key: string, value: string | number | boolean | null): void;
21
+ /**
22
+ * Convert a plain object row to a safe null-prototype row.
23
+ */
24
+ export declare function toSafeRow(plainRow: Record<string, unknown>): CsvRow;
9
25
  /** Parse CSV input string to array of row objects */
10
26
  export declare function parseCsv(input: string): {
11
27
  headers: string[];
@@ -14,7 +14,7 @@ import type { SimpleCommandNode } from "../ast/types.js";
14
14
  * Context needed for alias expansion operations
15
15
  */
16
16
  export interface AliasExpansionContext {
17
- env: Record<string, string | undefined>;
17
+ env: Map<string, string>;
18
18
  }
19
19
  /**
20
20
  * Expand alias in a SimpleCommandNode if applicable.
@@ -10,18 +10,18 @@
10
10
  * Get the effective IFS value from environment.
11
11
  * Returns DEFAULT_IFS if IFS is undefined, or the actual value (including empty string).
12
12
  */
13
- export declare function getIfs(env: Record<string, string>): string;
13
+ export declare function getIfs(env: Map<string, string>): string;
14
14
  /**
15
15
  * Check if IFS is set to empty string (disables word splitting).
16
16
  */
17
- export declare function isIfsEmpty(env: Record<string, string>): boolean;
17
+ export declare function isIfsEmpty(env: Map<string, string>): boolean;
18
18
  /**
19
19
  * Check if IFS contains only whitespace characters (space, tab, newline).
20
20
  * This affects how empty fields are handled in $@ and $* expansion.
21
21
  * When IFS has non-whitespace chars, empty params are preserved.
22
22
  * When IFS has only whitespace, empty params are dropped.
23
23
  */
24
- export declare function isIfsWhitespaceOnly(env: Record<string, string>): boolean;
24
+ export declare function isIfsWhitespaceOnly(env: Map<string, string>): boolean;
25
25
  /**
26
26
  * Build a regex-safe pattern from IFS characters for use in character classes.
27
27
  * E.g., for IFS=" \t\n", returns " \\t\\n" (escaped for [pattern] use)
@@ -31,7 +31,7 @@ export declare function buildIfsCharClassPattern(ifs: string): string;
31
31
  * Get the first character of IFS (used for joining with $* and ${!prefix*}).
32
32
  * Returns space if IFS is undefined, empty string if IFS is empty.
33
33
  */
34
- export declare function getIfsSeparator(env: Record<string, string>): string;
34
+ export declare function getIfsSeparator(env: Map<string, string>): string;
35
35
  /**
36
36
  * Advanced IFS splitting for the read builtin with proper whitespace/non-whitespace handling.
37
37
  *
@@ -18,7 +18,7 @@ export interface AssignmentResult {
18
18
  /** Accumulated xtrace output for assignments */
19
19
  xtraceOutput: string;
20
20
  /** Temporary assignments for prefix bindings (FOO=bar cmd) */
21
- tempAssignments: Record<string, string | undefined>;
21
+ tempAssignments: Map<string, string | undefined>;
22
22
  /** Error result if assignment failed */
23
23
  error?: ExecResult;
24
24
  }
@@ -261,8 +261,8 @@ export interface ExpansionState {
261
261
  * - {@link ExpansionState} - Expansion error capture
262
262
  */
263
263
  export interface InterpreterState extends VariableAttributeState, LocalScopingState, CallStackState, ControlFlowState, ProcessState, IOState, ExpansionState {
264
- /** Environment variables (exported to commands) */
265
- env: Record<string, string>;
264
+ /** Environment variables (exported to commands) - uses Map to prevent prototype pollution */
265
+ env: Map<string, string>;
266
266
  /** Current working directory */
267
267
  cwd: string;
268
268
  /** Previous directory (for `cd -`) */
package/dist/types.d.ts CHANGED
@@ -61,8 +61,8 @@ export interface CommandContext {
61
61
  fs: IFileSystem;
62
62
  /** Current working directory */
63
63
  cwd: string;
64
- /** Environment variables */
65
- env: Record<string, string>;
64
+ /** Environment variables - uses Map to prevent prototype pollution */
65
+ env: Map<string, string>;
66
66
  /**
67
67
  * Exported environment variables only.
68
68
  * Used by commands like printenv and env that should only show exported vars.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "just-bash",
3
- "version": "2.7.0",
3
+ "version": "2.7.1",
4
4
  "description": "A simulated bash environment with virtual filesystem",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,7 +0,0 @@
1
- #!/usr/bin/env node
2
- import{a as r,b as d}from"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";var u={name:"alias",summary:"define or display aliases",usage:"alias [name[=value] ...]",options:[" --help display this help and exit"]},o="BASH_ALIAS_",m={name:"alias",async execute(e,a){if(d(e))return r(u);if(e.length===0){let t="";for(let[i,s]of Object.entries(a.env))if(i.startsWith(o)){let n=i.slice(o.length);t+=`alias ${n}='${s}'
3
- `}return{stdout:t,stderr:"",exitCode:0}}let l=e[0]==="--"?e.slice(1):e;for(let t of l){let i=t.indexOf("=");if(i===-1){let s=o+t;return a.env[s]?{stdout:`alias ${t}='${a.env[s]}'
4
- `,stderr:"",exitCode:0}:{stdout:"",stderr:`alias: ${t}: not found
5
- `,exitCode:1}}else{let s=t.slice(0,i),n=t.slice(i+1);(n.startsWith("'")&&n.endsWith("'")||n.startsWith('"')&&n.endsWith('"'))&&(n=n.slice(1,-1)),a.env[o+s]=n}}return{stdout:"",stderr:"",exitCode:0}}},c={name:"unalias",async execute(e,a){if(d(e))return r({name:"unalias",summary:"remove alias definitions",usage:"unalias name [name ...]",options:["-a remove all aliases"," --help display this help and exit"]});if(e.length===0)return{stdout:"",stderr:`unalias: usage: unalias [-a] name [name ...]
6
- `,exitCode:1};if(e[0]==="-a"){for(let s of Object.keys(a.env))s.startsWith(o)&&delete a.env[s];return{stdout:"",stderr:"",exitCode:0}}let l=e[0]==="--"?e.slice(1):e,t=!1,i="";for(let s of l){let n=o+s;a.env[n]?delete a.env[n]:(i+=`unalias: ${s}: not found
7
- `,t=!0)}return{stdout:"",stderr:i,exitCode:t?1:0}}};export{m as aliasCommand,c as unaliasCommand};
@@ -1,21 +0,0 @@
1
- #!/usr/bin/env node
2
- import{k as C}from"./chunk-K5IXNHO5.js";import{a as te,b as ne,c as X}from"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";function K(e={}){let{fieldSep:t=/\s+/,maxIterations:n=1e4,maxRecursionDepth:i=100,fs:a,cwd:s,exec:o}=e;return{FS:" ",OFS:" ",ORS:`
3
- `,OFMT:"%.6g",NR:0,NF:0,FNR:0,FILENAME:"",RSTART:0,RLENGTH:-1,SUBSEP:"",fields:[],line:"",vars:{},arrays:{},arrayAliases:new Map,ARGC:0,ARGV:{},ENVIRON:{},functions:new Map,fieldSep:t,maxIterations:n,maxRecursionDepth:i,currentRecursionDepth:0,exitCode:0,shouldExit:!1,shouldNext:!1,shouldNextFile:!1,loopBreak:!1,loopContinue:!1,hasReturn:!1,inEndBlock:!1,output:"",openedFiles:new Set,fs:a,cwd:s,exec:o}}function re(e,t,n){switch(n){case"+":return e+t;case"-":return e-t;case"*":return e*t;case"/":return t!==0?e/t:0;case"%":return t!==0?e%t:0;case"^":case"**":return e**t;default:return 0}}function k(e){if(typeof e=="number")return e;let t=parseFloat(e);return Number.isNaN(t)?0:t}function m(e){return typeof e=="string"?e:(Number.isInteger(e),String(e))}async function G(e,t){if(e.type==="regex")return e.pattern;let n=m(await t.evalExpr(e));return n.startsWith("/")&&n.endsWith("/")&&(n=n.slice(1,-1)),n}async function se(e,t){return e?e.type==="variable"?e.name:e.type==="field"?`$${Math.floor(k(await t.evalExpr(e.index)))}`:"$0":"$0"}function ae(e,t){if(e==="$0")return t.line;if(e.startsWith("$")){let n=parseInt(e.slice(1),10)-1;return t.fields[n]||""}return m(t.vars[e]??"")}function oe(e,t,n){if(e==="$0")n.line=t,n.fields=n.FS===" "?t.trim().split(/\s+/).filter(Boolean):t.split(n.fieldSep),n.NF=n.fields.length;else if(e.startsWith("$")){let i=parseInt(e.slice(1),10)-1;for(;n.fields.length<=i;)n.fields.push("");n.fields[i]=t,n.NF=n.fields.length,n.line=n.fields.join(n.OFS)}else n.vars[e]=t}async function ge(e,t,n){return e.length===0?t.line.length:m(await n.evalExpr(e[0])).length}async function ke(e,t,n){if(e.length<2)return"";let i=m(await n.evalExpr(e[0])),a=Math.floor(k(await n.evalExpr(e[1])))-1;if(e.length>=3){let s=Math.floor(k(await n.evalExpr(e[2])));return i.substr(Math.max(0,a),s)}return i.substr(Math.max(0,a))}async function Ce(e,t,n){if(e.length<2)return 0;let i=m(await n.evalExpr(e[0])),a=m(await n.evalExpr(e[1])),s=i.indexOf(a);return s===-1?0:s+1}async function Le(e,t,n){if(e.length<2)return 0;let i=m(await n.evalExpr(e[0])),a=e[1];if(a.type!=="variable")return 0;let s=a.name,o=t.FS;if(e.length>=3){let h=e[2];if(h.type==="regex")o=new RegExp(h.pattern);else{let N=m(await n.evalExpr(h));o=N===" "?/\s+/:N}}else t.FS===" "&&(o=/\s+/);let l=i.split(o);t.arrays[s]={};for(let h=0;h<l.length;h++)t.arrays[s][String(h+1)]=l[h];return l.length}async function be(e,t,n){if(e.length<2)return 0;let i=await G(e[0],n),a=m(await n.evalExpr(e[1])),s=await se(e[2],n),o=ae(s,t);try{let l=new RegExp(i),h=o.replace(l,ce(a)),N=h!==o?1:0;return oe(s,h,t),N}catch{return 0}}async function Oe(e,t,n){if(e.length<2)return 0;let i=await G(e[0],n),a=m(await n.evalExpr(e[1])),s=await se(e[2],n),o=ae(s,t);try{let l=new RegExp(i,"g"),h=o.match(l),N=h?h.length:0,v=o.replace(l,ce(a));return oe(s,v,t),N}catch{return 0}}function ce(e){return t=>{let n="",i=0;for(;i<e.length;)if(e[i]==="\\"&&i+1<e.length){let a=e[i+1];a==="&"?(n+="&",i+=2):a==="\\"?(n+="\\",i+=2):(n+=e[i+1],i+=2)}else e[i]==="&"?(n+=t,i++):(n+=e[i],i++);return n}}async function Pe(e,t,n){if(e.length<2)return t.RSTART=0,t.RLENGTH=-1,0;let i=m(await n.evalExpr(e[0])),a=await G(e[1],n);try{let o=new RegExp(a).exec(i);if(o)return t.RSTART=o.index+1,t.RLENGTH=o[0].length,t.RSTART}catch{}return t.RSTART=0,t.RLENGTH=-1,0}async function Me(e,t,n){if(e.length<3)return"";let i=await G(e[0],n),a=m(await n.evalExpr(e[1])),s=m(await n.evalExpr(e[2])),o=e.length>=4?m(await n.evalExpr(e[3])):t.line;try{let l=s.toLowerCase()==="g",h=l?0:parseInt(s,10)||1;if(l){let N=new RegExp(i,"g");return o.replace(N,(v,...R)=>ie(a,v,R.slice(0,-2)))}else{let N=0,v=new RegExp(i,"g");return o.replace(v,(R,...I)=>(N++,N===h?ie(a,R,I.slice(0,-2)):R))}}catch{return o}}function ie(e,t,n){let i="",a=0;for(;a<e.length;)if(e[a]==="\\"&&a+1<e.length){let s=e[a+1];if(s==="&")i+="&",a+=2;else if(s==="0")i+=t,a+=2;else if(s>="1"&&s<="9"){let o=parseInt(s,10)-1;i+=n[o]||"",a+=2}else s==="n"?(i+=`
4
- `,a+=2):s==="t"?(i+=" ",a+=2):(i+=s,a+=2)}else e[a]==="&"?(i+=t,a++):(i+=e[a],a++);return i}async function Te(e,t,n){return e.length===0?"":m(await n.evalExpr(e[0])).toLowerCase()}async function Fe(e,t,n){return e.length===0?"":m(await n.evalExpr(e[0])).toUpperCase()}async function _e(e,t,n){if(e.length===0)return"";let i=m(await n.evalExpr(e[0])),a=[];for(let s=1;s<e.length;s++)a.push(await n.evalExpr(e[s]));return D(i,a)}async function Ge(e,t,n){return e.length===0?0:Math.floor(k(await n.evalExpr(e[0])))}async function De(e,t,n){return e.length===0?0:Math.sqrt(k(await n.evalExpr(e[0])))}async function xe(e,t,n){return e.length===0?0:Math.sin(k(await n.evalExpr(e[0])))}async function Ue(e,t,n){return e.length===0?0:Math.cos(k(await n.evalExpr(e[0])))}async function Be(e,t,n){let i=e.length>0?k(await n.evalExpr(e[0])):0,a=e.length>1?k(await n.evalExpr(e[1])):0;return Math.atan2(i,a)}async function He(e,t,n){return e.length===0?0:Math.log(k(await n.evalExpr(e[0])))}async function $e(e,t,n){return e.length===0?1:Math.exp(k(await n.evalExpr(e[0])))}function We(e,t,n){return t.random?t.random():Math.random()}async function Ve(e,t,n){let i=e.length>0?k(await n.evalExpr(e[0])):Date.now();return t.vars._srand_seed=i,i}function Xe(e,t){return()=>{throw new Error(`${e}() is not supported - ${t}`)}}function Q(e){return()=>{throw new Error(`function '${e}()' is not implemented`)}}function D(e,t){let n=0,i="",a=0;for(;a<e.length;)if(e[a]==="%"&&a+1<e.length){let s=a+1,o="",l="",h="",N,v=s;for(;s<e.length&&/\d/.test(e[s]);)s++;s>v&&e[s]==="$"?(N=parseInt(e.substring(v,s),10)-1,s++):s=v;let R=()=>{if(s<e.length){if(s+1<e.length&&(e[s]==="h"&&e[s+1]==="h"||e[s]==="l"&&e[s+1]==="l")){s+=2;return}/[lzjh]/.test(e[s])&&s++}};for(;s<e.length&&/[-+ #0]/.test(e[s]);)o+=e[s++];if(e[s]==="*"){let c=t[n++],p=c!==void 0?Math.floor(Number(c)):0;p<0?(o+="-",l=String(-p)):l=String(p),s++}else for(;s<e.length&&/\d/.test(e[s]);)l+=e[s++];if(e[s]===".")if(s++,e[s]==="*"){let c=t[n++];h=String(c!==void 0?Math.floor(Number(c)):0),s++}else for(;s<e.length&&/\d/.test(e[s]);)h+=e[s++];R();let I=e[s],w=t[N!==void 0?N:n];switch(I){case"s":{let c=w!==void 0?String(w):"";if(h&&(c=c.substring(0,parseInt(h,10))),l){let p=parseInt(l,10);o.includes("-")?c=c.padEnd(p):c=c.padStart(p)}i+=c,N===void 0&&n++;break}case"d":case"i":{let c=w!==void 0?Math.floor(Number(w)):0;Number.isNaN(c)&&(c=0);let p=c<0,E=Math.abs(c).toString();if(h){let L=parseInt(h,10);E=E.padStart(L,"0")}let d="";p?d="-":o.includes("+")?d="+":o.includes(" ")&&(d=" ");let y=d+E;if(l){let L=parseInt(l,10);o.includes("-")?y=y.padEnd(L):o.includes("0")&&!h?y=d+E.padStart(L-d.length,"0"):y=y.padStart(L)}i+=y,N===void 0&&n++;break}case"f":{let c=w!==void 0?Number(w):0;Number.isNaN(c)&&(c=0);let p=h?parseInt(h,10):6,E=c.toFixed(p);if(l){let d=parseInt(l,10);o.includes("-")?E=E.padEnd(d):E=E.padStart(d)}i+=E,N===void 0&&n++;break}case"e":case"E":{let c=w!==void 0?Number(w):0;Number.isNaN(c)&&(c=0);let p=h?parseInt(h,10):6,E=c.toExponential(p);if(I==="E"&&(E=E.toUpperCase()),l){let d=parseInt(l,10);o.includes("-")?E=E.padEnd(d):E=E.padStart(d)}i+=E,N===void 0&&n++;break}case"g":case"G":{let c=w!==void 0?Number(w):0;Number.isNaN(c)&&(c=0);let p=h?parseInt(h,10):6,E=c!==0?Math.floor(Math.log10(Math.abs(c))):0,d;if(c===0?d="0":E<-4||E>=p?(d=c.toExponential(p-1),I==="G"&&(d=d.toUpperCase())):d=c.toPrecision(p),d.includes(".")&&(d=d.replace(/\.?0+$/,"").replace(/\.?0+e/,"e")),d.includes("e")&&(d=d.replace(/\.?0+e/,"e")),l){let y=parseInt(l,10);o.includes("-")?d=d.padEnd(y):d=d.padStart(y)}i+=d,N===void 0&&n++;break}case"x":case"X":{let c=w!==void 0?Math.floor(Number(w)):0;Number.isNaN(c)&&(c=0);let p=Math.abs(c).toString(16);if(I==="X"&&(p=p.toUpperCase()),h){let y=parseInt(h,10);p=p.padStart(y,"0")}let E=c<0?"-":"",d=E+p;if(l){let y=parseInt(l,10);o.includes("-")?d=d.padEnd(y):o.includes("0")&&!h?d=E+p.padStart(y-E.length,"0"):d=d.padStart(y)}i+=d,N===void 0&&n++;break}case"o":{let c=w!==void 0?Math.floor(Number(w)):0;Number.isNaN(c)&&(c=0);let p=Math.abs(c).toString(8);if(h){let y=parseInt(h,10);p=p.padStart(y,"0")}let E=c<0?"-":"",d=E+p;if(l){let y=parseInt(l,10);o.includes("-")?d=d.padEnd(y):o.includes("0")&&!h?d=E+p.padStart(y-E.length,"0"):d=d.padStart(y)}i+=d,N===void 0&&n++;break}case"c":{typeof w=="number"?i+=String.fromCharCode(w):i+=String(w??"").charAt(0)||"",N===void 0&&n++;break}case"%":i+="%";break;default:i+=e.substring(a,s+1)}a=s+1}else if(e[a]==="\\"&&a+1<e.length){let s=e[a+1];switch(s){case"n":i+=`
5
- `;break;case"t":i+=" ";break;case"r":i+="\r";break;case"\\":i+="\\";break;default:i+=s}a+=2}else i+=e[a++];return i}var le={length:ge,substr:ke,index:Ce,split:Le,sub:be,gsub:Oe,match:Pe,gensub:Me,tolower:Te,toupper:Fe,sprintf:_e,int:Ge,sqrt:De,sin:xe,cos:Ue,atan2:Be,log:He,exp:$e,rand:We,srand:Ve,system:Xe("system","shell execution not allowed in sandboxed environment"),close:()=>0,fflush:()=>0,systime:Q("systime"),mktime:Q("mktime"),strftime:Q("strftime")};function g(e){return typeof e=="number"?e!==0:!(e===""||e==="0")}function A(e){if(typeof e=="number")return e;let t=parseFloat(e);return Number.isNaN(t)?0:t}function S(e){return typeof e=="string"?e:(Number.isInteger(e),String(e))}function j(e){if(typeof e=="number")return!0;let t=String(e).trim();return t===""?!1:!Number.isNaN(Number(t))}function T(e,t){try{return new RegExp(e).test(t)}catch{return!1}}function ue(e,t){return t===""?[]:e.FS===" "?t.trim().split(/\s+/).filter(Boolean):t.split(e.fieldSep)}function x(e,t){return t===0?e.line:t<0||t>e.fields.length?"":e.fields[t-1]??""}function q(e,t,n){if(t===0)e.line=S(n),e.fields=ue(e,e.line),e.NF=e.fields.length;else if(t>0){for(;e.fields.length<t;)e.fields.push("");e.fields[t-1]=S(n),e.NF=e.fields.length,e.line=e.fields.join(e.OFS)}}function O(e,t){e.line=t,e.fields=ue(e,t),e.NF=e.fields.length}function he(e,t){if(e.FS=t,t===" ")e.fieldSep=/\s+/;else try{e.fieldSep=new RegExp(t)}catch{e.fieldSep=new RegExp(t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"))}}function U(e,t){switch(t){case"FS":return e.FS;case"OFS":return e.OFS;case"ORS":return e.ORS;case"OFMT":return e.OFMT;case"NR":return e.NR;case"NF":return e.NF;case"FNR":return e.FNR;case"FILENAME":return e.FILENAME;case"RSTART":return e.RSTART;case"RLENGTH":return e.RLENGTH;case"SUBSEP":return e.SUBSEP;case"ARGC":return e.ARGC}return e.vars[t]??""}function P(e,t,n){switch(t){case"FS":he(e,S(n));return;case"OFS":e.OFS=S(n);return;case"ORS":e.ORS=S(n);return;case"OFMT":e.OFMT=S(n);return;case"NR":e.NR=Math.floor(A(n));return;case"NF":{let i=Math.floor(A(n));if(i<e.NF)e.fields=e.fields.slice(0,i),e.line=e.fields.join(e.OFS);else if(i>e.NF){for(;e.fields.length<i;)e.fields.push("");e.line=e.fields.join(e.OFS)}e.NF=i;return}case"FNR":e.FNR=Math.floor(A(n));return;case"FILENAME":e.FILENAME=S(n);return;case"RSTART":e.RSTART=Math.floor(A(n));return;case"RLENGTH":e.RLENGTH=Math.floor(A(n));return;case"SUBSEP":e.SUBSEP=S(n);return}e.vars[t]=n}function F(e,t){let n=t,i=new Set,a=e.arrayAliases.get(n);for(;a!==void 0&&!i.has(n);)i.add(n),n=a,a=e.arrayAliases.get(n);return n}function B(e,t,n){if(t==="ARGV")return e.ARGV[n]??"";if(t==="ENVIRON")return e.ENVIRON[n]??"";let i=F(e,t);return e.arrays[i]?.[n]??""}function z(e,t,n,i){let a=F(e,t);e.arrays[a]||(e.arrays[a]={}),e.arrays[a][n]=i}function pe(e,t,n){if(t==="ARGV")return e.ARGV[n]!==void 0;if(t==="ENVIRON")return e.ENVIRON[n]!==void 0;let i=F(e,t);return e.arrays[i]?.[n]!==void 0}function fe(e,t,n){let i=F(e,t);e.arrays[i]&&delete e.arrays[i][n]}function de(e,t){let n=F(e,t);delete e.arrays[n]}var J=null;function Ee(e){J=e}async function f(e,t){switch(t.type){case"number":return t.value;case"string":return t.value;case"regex":return T(t.pattern,e.line)?1:0;case"field":return Ke(e,t);case"variable":return U(e,t.name);case"array_access":return Qe(e,t);case"binary":return je(e,t);case"unary":return Je(e,t);case"ternary":return g(await f(e,t.condition))?await f(e,t.consequent):await f(e,t.alternate);case"call":return Ze(e,t.name,t.args);case"assignment":return et(e,t);case"pre_increment":return tt(e,t.operand);case"pre_decrement":return nt(e,t.operand);case"post_increment":return rt(e,t.operand);case"post_decrement":return it(e,t.operand);case"in":return st(e,t.key,t.array);case"getline":return at(e,t.variable,t.file,t.command);case"tuple":return lt(e,t.elements);default:return""}}async function Ke(e,t){let n=Math.floor(A(await f(e,t.index)));return x(e,n)}async function Qe(e,t){let n=S(await f(e,t.key));return B(e,t.array,n)}async function je(e,t){let n=t.operator;if(n==="||")return g(await f(e,t.left))||g(await f(e,t.right))?1:0;if(n==="&&")return g(await f(e,t.left))&&g(await f(e,t.right))?1:0;if(n==="~"){let l=await f(e,t.left),h=t.right.type==="regex"?t.right.pattern:S(await f(e,t.right));try{return new RegExp(h).test(S(l))?1:0}catch{return 0}}if(n==="!~"){let l=await f(e,t.left),h=t.right.type==="regex"?t.right.pattern:S(await f(e,t.right));try{return new RegExp(h).test(S(l))?0:1}catch{return 1}}let i=await f(e,t.left),a=await f(e,t.right);if(n===" ")return S(i)+S(a);if(qe(n))return ze(i,a,n);let s=A(i),o=A(a);return re(s,o,n)}function qe(e){return["<","<=",">",">=","==","!="].includes(e)}function ze(e,t,n){let i=j(e),a=j(t);if(i&&a){let l=A(e),h=A(t);switch(n){case"<":return l<h?1:0;case"<=":return l<=h?1:0;case">":return l>h?1:0;case">=":return l>=h?1:0;case"==":return l===h?1:0;case"!=":return l!==h?1:0}}let s=S(e),o=S(t);switch(n){case"<":return s<o?1:0;case"<=":return s<=o?1:0;case">":return s>o?1:0;case">=":return s>=o?1:0;case"==":return s===o?1:0;case"!=":return s!==o?1:0}return 0}async function Je(e,t){let n=await f(e,t.operand);switch(t.operator){case"!":return g(n)?0:1;case"-":return-A(n);case"+":return+A(n);default:return n}}async function Ze(e,t,n){let i=le[t];if(i)return i(n,e,{evalExpr:s=>f(e,s)});let a=e.functions.get(t);return a?Ye(e,a,n):""}async function Ye(e,t,n){if(e.currentRecursionDepth++,e.currentRecursionDepth>e.maxRecursionDepth)throw e.currentRecursionDepth--,new C(`awk: recursion depth exceeded maximum (${e.maxRecursionDepth})`,"recursion",e.output);let i={};for(let o of t.params)i[o]=e.vars[o];let a=[];for(let o=0;o<t.params.length;o++){let l=t.params[o];if(o<n.length){let h=n[o];h.type==="variable"&&(e.arrayAliases.set(l,h.name),a.push(l));let N=await f(e,h);e.vars[l]=N}else e.vars[l]=""}e.hasReturn=!1,e.returnValue=void 0,J&&await J(e,t.body.statements);let s=e.returnValue??"";for(let o of t.params)i[o]!==void 0?e.vars[o]=i[o]:delete e.vars[o];for(let o of a)e.arrayAliases.delete(o);return e.hasReturn=!1,e.returnValue=void 0,e.currentRecursionDepth--,s}async function et(e,t){let n=await f(e,t.value),i=t.target,a=t.operator,s;if(a==="=")s=n;else{let o;if(i.type==="field"){let N=Math.floor(A(await f(e,i.index)));o=x(e,N)}else if(i.type==="variable")o=U(e,i.name);else{let N=S(await f(e,i.key));o=B(e,i.array,N)}let l=A(o),h=A(n);switch(a){case"+=":s=l+h;break;case"-=":s=l-h;break;case"*=":s=l*h;break;case"/=":s=h!==0?l/h:0;break;case"%=":s=h!==0?l%h:0;break;case"^=":s=l**h;break;default:s=n}}if(i.type==="field"){let o=Math.floor(A(await f(e,i.index)));q(e,o,s)}else if(i.type==="variable")P(e,i.name,s);else{let o=S(await f(e,i.key));z(e,i.array,o,s)}return s}async function H(e,t,n,i){let a;if(t.type==="field"){let s=Math.floor(A(await f(e,t.index)));a=A(x(e,s)),q(e,s,a+n)}else if(t.type==="variable")a=A(U(e,t.name)),P(e,t.name,a+n);else{let s=S(await f(e,t.key));a=A(B(e,t.array,s)),z(e,t.array,s,a+n)}return i?a+n:a}async function tt(e,t){return H(e,t,1,!0)}async function nt(e,t){return H(e,t,-1,!0)}async function rt(e,t){return H(e,t,1,!1)}async function it(e,t){return H(e,t,-1,!1)}async function st(e,t,n){let i;if(t.type==="tuple"){let a=[];for(let s of t.elements)a.push(S(await f(e,s)));i=a.join(e.SUBSEP)}else i=S(await f(e,t));return pe(e,n,i)?1:0}async function at(e,t,n,i){if(i)return ot(e,t,i);if(n)return ct(e,t,n);if(!e.lines||e.lineIndex===void 0)return-1;let a=e.lineIndex+1;if(a>=e.lines.length)return 0;let s=e.lines[a];return t?P(e,t,s):O(e,s),e.NR++,e.lineIndex=a,1}async function ot(e,t,n){if(!e.exec)return-1;let i=S(await f(e,n)),a=`__cmd_${i}`,s=`__cmdi_${i}`,o,l;if(e.vars[a]===void 0)try{o=(await e.exec(i)).stdout.split(`
6
- `),o.length>0&&o[o.length-1]===""&&o.pop(),e.vars[a]=JSON.stringify(o),e.vars[s]=-1,l=-1}catch{return-1}else o=JSON.parse(e.vars[a]),l=e.vars[s];let h=l+1;if(h>=o.length)return 0;let N=o[h];return e.vars[s]=h,t?P(e,t,N):O(e,N),1}async function ct(e,t,n){if(!e.fs||!e.cwd)return-1;let i=S(await f(e,n));if(i==="/dev/null")return 0;let a=e.fs.resolvePath(e.cwd,i),s=`__fc_${a}`,o=`__fi_${a}`,l,h;if(e.vars[s]===void 0)try{l=(await e.fs.readFile(a)).split(`
7
- `),l.length>0&&l[l.length-1]===""&&l.pop(),e.vars[s]=JSON.stringify(l),e.vars[o]=-1,h=-1}catch{return-1}else l=JSON.parse(e.vars[s]),h=e.vars[o];let N=h+1;if(N>=l.length)return 0;let v=l[N];return e.vars[o]=N,t?P(e,t,v):O(e,v),1}async function lt(e,t){if(t.length===0)return"";for(let n=0;n<t.length-1;n++)await f(e,t[n]);return f(e,t[t.length-1])}Ee(M);async function M(e,t){for(let n of t)if(await b(e,n),ut(e))break}function ut(e){return e.shouldExit||e.shouldNext||e.shouldNextFile||e.loopBreak||e.loopContinue||e.hasReturn}async function b(e,t){switch(t.type){case"block":await M(e,t.statements);break;case"expr_stmt":await f(e,t.expression);break;case"print":await ht(e,t.args,t.output);break;case"printf":await pt(e,t.format,t.args,t.output);break;case"if":await ft(e,t);break;case"while":await dt(e,t);break;case"do_while":await Et(e,t);break;case"for":await Nt(e,t);break;case"for_in":await St(e,t);break;case"break":e.loopBreak=!0;break;case"continue":e.loopContinue=!0;break;case"next":e.shouldNext=!0;break;case"nextfile":e.shouldNextFile=!0;break;case"exit":e.shouldExit=!0,e.exitCode=t.code?Math.floor(A(await f(e,t.code))):0;break;case"return":e.hasReturn=!0,e.returnValue=t.value?await f(e,t.value):"";break;case"delete":await yt(e,t.target);break}}async function ht(e,t,n){let i=[];for(let s of t){let o=await f(e,s);typeof o=="number"?Number.isInteger(o)&&Math.abs(o)<Number.MAX_SAFE_INTEGER?i.push(String(o)):i.push(D(e.OFMT,[o])):i.push(S(o))}let a=i.join(e.OFS)+e.ORS;n?await Ne(e,n.redirect,n.file,a):e.output+=a}async function pt(e,t,n,i){let a=S(await f(e,t)),s=[];for(let l of n)s.push(await f(e,l));let o=D(a,s);i?await Ne(e,i.redirect,i.file,o):e.output+=o}async function Ne(e,t,n,i){if(!e.fs||!e.cwd){e.output+=i;return}let a=S(await f(e,n)),s=e.fs.resolvePath(e.cwd,a);t===">"?e.openedFiles.has(s)?await e.fs.appendFile(s,i):(await e.fs.writeFile(s,i),e.openedFiles.add(s)):(e.openedFiles.has(s)||e.openedFiles.add(s),await e.fs.appendFile(s,i))}async function ft(e,t){g(await f(e,t.condition))?await b(e,t.consequent):t.alternate&&await b(e,t.alternate)}async function dt(e,t){let n=0;for(;g(await f(e,t.condition));){if(n++,n>e.maxIterations)throw new C(`awk: while loop exceeded maximum iterations (${e.maxIterations})`,"iterations",e.output);if(e.loopContinue=!1,await b(e,t.body),e.loopBreak){e.loopBreak=!1;break}if(e.shouldExit||e.shouldNext||e.hasReturn)break}}async function Et(e,t){let n=0;do{if(n++,n>e.maxIterations)throw new C(`awk: do-while loop exceeded maximum iterations (${e.maxIterations})`,"iterations",e.output);if(e.loopContinue=!1,await b(e,t.body),e.loopBreak){e.loopBreak=!1;break}if(e.shouldExit||e.shouldNext||e.hasReturn)break}while(g(await f(e,t.condition)))}async function Nt(e,t){t.init&&await f(e,t.init);let n=0;for(;!t.condition||g(await f(e,t.condition));){if(n++,n>e.maxIterations)throw new C(`awk: for loop exceeded maximum iterations (${e.maxIterations})`,"iterations",e.output);if(e.loopContinue=!1,await b(e,t.body),e.loopBreak){e.loopBreak=!1;break}if(e.shouldExit||e.shouldNext||e.hasReturn)break;t.update&&await f(e,t.update)}}async function St(e,t){let n=e.arrays[t.array];if(n)for(let i of Object.keys(n)){if(e.vars[t.variable]=i,e.loopContinue=!1,await b(e,t.body),e.loopBreak){e.loopBreak=!1;break}if(e.shouldExit||e.shouldNext||e.hasReturn)break}}async function yt(e,t){if(t.type==="array_access"){let n=S(await f(e,t.key));fe(e,t.array,n)}else t.type==="variable"&&de(e,t.name)}var _=class{ctx;program=null;rangeStates=[];constructor(t){this.ctx=t}execute(t){this.program=t,this.ctx.output="";for(let n of t.functions)this.ctx.functions.set(n.name,n);this.rangeStates=t.rules.map(()=>!1)}async executeBegin(){if(this.program){for(let t of this.program.rules)if(t.pattern?.type==="begin"&&(await M(this.ctx,t.action.statements),this.ctx.shouldExit))break}}async executeLine(t){if(!(!this.program||this.ctx.shouldExit)){O(this.ctx,t),this.ctx.NR++,this.ctx.FNR++,this.ctx.shouldNext=!1;for(let n=0;n<this.program.rules.length&&!(this.ctx.shouldExit||this.ctx.shouldNext||this.ctx.shouldNextFile);n++){let i=this.program.rules[n];i.pattern?.type==="begin"||i.pattern?.type==="end"||await this.matchesRule(i,n)&&await M(this.ctx,i.action.statements)}}}async executeEnd(){if(this.program&&!this.ctx.inEndBlock){this.ctx.inEndBlock=!0,this.ctx.shouldExit=!1;for(let t of this.program.rules)if(t.pattern?.type==="end"&&(await M(this.ctx,t.action.statements),this.ctx.shouldExit))break;this.ctx.inEndBlock=!1}}getOutput(){return this.ctx.output}getExitCode(){return this.ctx.exitCode}getContext(){return this.ctx}async matchesRule(t,n){let i=t.pattern;if(!i)return!0;switch(i.type){case"begin":case"end":return!1;case"regex_pattern":return T(i.pattern,this.ctx.line);case"expr_pattern":return g(await f(this.ctx,i.expression));case"range":{let a=await this.matchPattern(i.start),s=await this.matchPattern(i.end);return this.rangeStates[n]?(s&&(this.rangeStates[n]=!1),!0):a?(this.rangeStates[n]=!0,s&&(this.rangeStates[n]=!1),!0):!1}default:return!1}}async matchPattern(t){switch(t.type){case"regex_pattern":return T(t.pattern,this.ctx.line);case"expr_pattern":return g(await f(this.ctx,t.expression));default:return!1}}};var r;(function(e){e.NUMBER="NUMBER",e.STRING="STRING",e.REGEX="REGEX",e.IDENT="IDENT",e.BEGIN="BEGIN",e.END="END",e.IF="IF",e.ELSE="ELSE",e.WHILE="WHILE",e.DO="DO",e.FOR="FOR",e.IN="IN",e.BREAK="BREAK",e.CONTINUE="CONTINUE",e.NEXT="NEXT",e.NEXTFILE="NEXTFILE",e.EXIT="EXIT",e.RETURN="RETURN",e.DELETE="DELETE",e.FUNCTION="FUNCTION",e.PRINT="PRINT",e.PRINTF="PRINTF",e.GETLINE="GETLINE",e.PLUS="PLUS",e.MINUS="MINUS",e.STAR="STAR",e.SLASH="SLASH",e.PERCENT="PERCENT",e.CARET="CARET",e.EQ="EQ",e.NE="NE",e.LT="LT",e.GT="GT",e.LE="LE",e.GE="GE",e.MATCH="MATCH",e.NOT_MATCH="NOT_MATCH",e.AND="AND",e.OR="OR",e.NOT="NOT",e.ASSIGN="ASSIGN",e.PLUS_ASSIGN="PLUS_ASSIGN",e.MINUS_ASSIGN="MINUS_ASSIGN",e.STAR_ASSIGN="STAR_ASSIGN",e.SLASH_ASSIGN="SLASH_ASSIGN",e.PERCENT_ASSIGN="PERCENT_ASSIGN",e.CARET_ASSIGN="CARET_ASSIGN",e.INCREMENT="INCREMENT",e.DECREMENT="DECREMENT",e.QUESTION="QUESTION",e.COLON="COLON",e.COMMA="COMMA",e.SEMICOLON="SEMICOLON",e.NEWLINE="NEWLINE",e.LPAREN="LPAREN",e.RPAREN="RPAREN",e.LBRACE="LBRACE",e.RBRACE="RBRACE",e.LBRACKET="LBRACKET",e.RBRACKET="RBRACKET",e.DOLLAR="DOLLAR",e.APPEND="APPEND",e.PIPE="PIPE",e.EOF="EOF"})(r||(r={}));var Rt={BEGIN:r.BEGIN,END:r.END,if:r.IF,else:r.ELSE,while:r.WHILE,do:r.DO,for:r.FOR,in:r.IN,break:r.BREAK,continue:r.CONTINUE,next:r.NEXT,nextfile:r.NEXTFILE,exit:r.EXIT,return:r.RETURN,delete:r.DELETE,function:r.FUNCTION,print:r.PRINT,printf:r.PRINTF,getline:r.GETLINE};function At(e){return e.replace(/\[\[:space:\]\]/g,"[ \\t\\n\\r\\f\\v]").replace(/\[\[:blank:\]\]/g,"[ \\t]").replace(/\[\[:alpha:\]\]/g,"[a-zA-Z]").replace(/\[\[:digit:\]\]/g,"[0-9]").replace(/\[\[:alnum:\]\]/g,"[a-zA-Z0-9]").replace(/\[\[:upper:\]\]/g,"[A-Z]").replace(/\[\[:lower:\]\]/g,"[a-z]").replace(/\[\[:punct:\]\]/g,"[!\"#$%&'()*+,\\-./:;<=>?@\\[\\]\\\\^_`{|}~]").replace(/\[\[:xdigit:\]\]/g,"[0-9A-Fa-f]").replace(/\[\[:graph:\]\]/g,"[!-~]").replace(/\[\[:print:\]\]/g,"[ -~]").replace(/\[\[:cntrl:\]\]/g,"[\\x00-\\x1f\\x7f]")}var $=class{input;pos=0;line=1;column=1;lastTokenType=null;constructor(t){this.input=t}tokenize(){let t=[];for(;this.pos<this.input.length;){let n=this.nextToken();n&&(t.push(n),this.lastTokenType=n.type)}return t.push(this.makeToken(r.EOF,"")),t}makeToken(t,n){return{type:t,value:n,line:this.line,column:this.column}}peek(t=0){return this.input[this.pos+t]||""}advance(){let t=this.input[this.pos++]||"";return t===`
8
- `?(this.line++,this.column=1):this.column++,t}skipWhitespace(){for(;this.pos<this.input.length;){let t=this.peek();if(t===" "||t===" "||t==="\r")this.advance();else if(t==="\\")if(this.peek(1)===`
9
- `)this.advance(),this.advance();else break;else if(t==="#")for(;this.pos<this.input.length&&this.peek()!==`
10
- `;)this.advance();else break}}nextToken(){if(this.skipWhitespace(),this.pos>=this.input.length)return null;let t=this.line,n=this.column,i=this.peek();return i===`
11
- `?(this.advance(),{type:r.NEWLINE,value:`
12
- `,line:t,column:n}):i==='"'?this.readString():i==="/"&&this.canBeRegex()?this.readRegex():this.isDigit(i)||i==="."&&this.isDigit(this.peek(1))?this.readNumber():this.isAlpha(i)||i==="_"?this.readIdentifier():this.readOperator()}canBeRegex(){return new Set([null,r.NEWLINE,r.SEMICOLON,r.LBRACE,r.RBRACE,r.LPAREN,r.LBRACKET,r.COMMA,r.ASSIGN,r.PLUS_ASSIGN,r.MINUS_ASSIGN,r.STAR_ASSIGN,r.SLASH_ASSIGN,r.PERCENT_ASSIGN,r.CARET_ASSIGN,r.AND,r.OR,r.NOT,r.MATCH,r.NOT_MATCH,r.QUESTION,r.COLON,r.LT,r.GT,r.LE,r.GE,r.EQ,r.NE,r.PLUS,r.MINUS,r.STAR,r.PERCENT,r.CARET,r.PRINT,r.PRINTF,r.IF,r.WHILE,r.DO,r.FOR,r.RETURN]).has(this.lastTokenType)}readString(){let t=this.line,n=this.column;this.advance();let i="";for(;this.pos<this.input.length&&this.peek()!=='"';)if(this.peek()==="\\"){this.advance();let a=this.advance();switch(a){case"n":i+=`
13
- `;break;case"t":i+=" ";break;case"r":i+="\r";break;case"f":i+="\f";break;case"b":i+="\b";break;case"v":i+="\v";break;case"a":i+="\x07";break;case"\\":i+="\\";break;case'"':i+='"';break;case"/":i+="/";break;case"x":{let s="";for(;s.length<2&&/[0-9a-fA-F]/.test(this.peek());)s+=this.advance();s.length>0?i+=String.fromCharCode(parseInt(s,16)):i+="x";break}default:if(/[0-7]/.test(a)){let s=a;for(;s.length<3&&/[0-7]/.test(this.peek());)s+=this.advance();i+=String.fromCharCode(parseInt(s,8))}else i+=a}}else i+=this.advance();return this.peek()==='"'&&this.advance(),{type:r.STRING,value:i,line:t,column:n}}readRegex(){let t=this.line,n=this.column;this.advance();let i="";for(;this.pos<this.input.length&&this.peek()!=="/";)if(this.peek()==="\\")i+=this.advance(),this.pos<this.input.length&&(i+=this.advance());else{if(this.peek()===`
14
- `)break;i+=this.advance()}return this.peek()==="/"&&this.advance(),i=At(i),{type:r.REGEX,value:i,line:t,column:n}}readNumber(){let t=this.line,n=this.column,i="";for(;this.isDigit(this.peek());)i+=this.advance();if(this.peek()==="."&&this.isDigit(this.peek(1)))for(i+=this.advance();this.isDigit(this.peek());)i+=this.advance();if(this.peek()==="e"||this.peek()==="E")for(i+=this.advance(),(this.peek()==="+"||this.peek()==="-")&&(i+=this.advance());this.isDigit(this.peek());)i+=this.advance();return{type:r.NUMBER,value:parseFloat(i),line:t,column:n}}readIdentifier(){let t=this.line,n=this.column,i="";for(;this.isAlphaNumeric(this.peek())||this.peek()==="_";)i+=this.advance();let a=Rt[i];return a?{type:a,value:i,line:t,column:n}:{type:r.IDENT,value:i,line:t,column:n}}readOperator(){let t=this.line,n=this.column,i=this.advance(),a=this.peek();switch(i){case"+":return a==="+"?(this.advance(),{type:r.INCREMENT,value:"++",line:t,column:n}):a==="="?(this.advance(),{type:r.PLUS_ASSIGN,value:"+=",line:t,column:n}):{type:r.PLUS,value:"+",line:t,column:n};case"-":return a==="-"?(this.advance(),{type:r.DECREMENT,value:"--",line:t,column:n}):a==="="?(this.advance(),{type:r.MINUS_ASSIGN,value:"-=",line:t,column:n}):{type:r.MINUS,value:"-",line:t,column:n};case"*":return a==="*"?(this.advance(),{type:r.CARET,value:"**",line:t,column:n}):a==="="?(this.advance(),{type:r.STAR_ASSIGN,value:"*=",line:t,column:n}):{type:r.STAR,value:"*",line:t,column:n};case"/":return a==="="?(this.advance(),{type:r.SLASH_ASSIGN,value:"/=",line:t,column:n}):{type:r.SLASH,value:"/",line:t,column:n};case"%":return a==="="?(this.advance(),{type:r.PERCENT_ASSIGN,value:"%=",line:t,column:n}):{type:r.PERCENT,value:"%",line:t,column:n};case"^":return a==="="?(this.advance(),{type:r.CARET_ASSIGN,value:"^=",line:t,column:n}):{type:r.CARET,value:"^",line:t,column:n};case"=":return a==="="?(this.advance(),{type:r.EQ,value:"==",line:t,column:n}):{type:r.ASSIGN,value:"=",line:t,column:n};case"!":return a==="="?(this.advance(),{type:r.NE,value:"!=",line:t,column:n}):a==="~"?(this.advance(),{type:r.NOT_MATCH,value:"!~",line:t,column:n}):{type:r.NOT,value:"!",line:t,column:n};case"<":return a==="="?(this.advance(),{type:r.LE,value:"<=",line:t,column:n}):{type:r.LT,value:"<",line:t,column:n};case">":return a==="="?(this.advance(),{type:r.GE,value:">=",line:t,column:n}):a===">"?(this.advance(),{type:r.APPEND,value:">>",line:t,column:n}):{type:r.GT,value:">",line:t,column:n};case"&":return a==="&"?(this.advance(),{type:r.AND,value:"&&",line:t,column:n}):{type:r.IDENT,value:"&",line:t,column:n};case"|":return a==="|"?(this.advance(),{type:r.OR,value:"||",line:t,column:n}):{type:r.PIPE,value:"|",line:t,column:n};case"~":return{type:r.MATCH,value:"~",line:t,column:n};case"?":return{type:r.QUESTION,value:"?",line:t,column:n};case":":return{type:r.COLON,value:":",line:t,column:n};case",":return{type:r.COMMA,value:",",line:t,column:n};case";":return{type:r.SEMICOLON,value:";",line:t,column:n};case"(":return{type:r.LPAREN,value:"(",line:t,column:n};case")":return{type:r.RPAREN,value:")",line:t,column:n};case"{":return{type:r.LBRACE,value:"{",line:t,column:n};case"}":return{type:r.RBRACE,value:"}",line:t,column:n};case"[":return{type:r.LBRACKET,value:"[",line:t,column:n};case"]":return{type:r.RBRACKET,value:"]",line:t,column:n};case"$":return{type:r.DOLLAR,value:"$",line:t,column:n};default:return{type:r.IDENT,value:i,line:t,column:n}}}isDigit(t){return t>="0"&&t<="9"}isAlpha(t){return t>="a"&&t<="z"||t>="A"&&t<="Z"}isAlphaNumeric(t){return this.isDigit(t)||this.isAlpha(t)}};var u={LPAREN:"LPAREN",RPAREN:"RPAREN",QUESTION:"QUESTION",NEWLINE:"NEWLINE",SEMICOLON:"SEMICOLON",RBRACE:"RBRACE",COMMA:"COMMA",PIPE:"PIPE",GT:"GT",APPEND:"APPEND",AND:"AND",OR:"OR",ASSIGN:"ASSIGN",PLUS_ASSIGN:"PLUS_ASSIGN",MINUS_ASSIGN:"MINUS_ASSIGN",STAR_ASSIGN:"STAR_ASSIGN",SLASH_ASSIGN:"SLASH_ASSIGN",PERCENT_ASSIGN:"PERCENT_ASSIGN",CARET_ASSIGN:"CARET_ASSIGN",RBRACKET:"RBRACKET",COLON:"COLON",IN:"IN",PRINT:"PRINT",PRINTF:"PRINTF",IDENT:"IDENT",LT:"LT",LE:"LE",GE:"GE",EQ:"EQ",NE:"NE",MATCH:"MATCH",NOT_MATCH:"NOT_MATCH",NUMBER:"NUMBER",STRING:"STRING",DOLLAR:"DOLLAR",NOT:"NOT",MINUS:"MINUS",PLUS:"PLUS",INCREMENT:"INCREMENT",DECREMENT:"DECREMENT"};function Ie(e){e.expect(u.PRINT);let t=[];if(e.check(u.NEWLINE)||e.check(u.SEMICOLON)||e.check(u.RBRACE)||e.check(u.PIPE)||e.check(u.GT)||e.check(u.APPEND))t.push({type:"field",index:{type:"number",value:0}});else for(t.push(W(e));e.check(u.COMMA);)e.advance(),t.push(W(e));let n;return e.check(u.GT)?(e.advance(),n={redirect:">",file:e.parsePrimary()}):e.check(u.APPEND)&&(e.advance(),n={redirect:">>",file:e.parsePrimary()}),{type:"print",args:t,output:n}}function W(e){return It(e)?Z(e,!0):Z(e,!1)}function Z(e,t){let n=t?e.parseTernary():wt(e);if(e.match(u.ASSIGN,u.PLUS_ASSIGN,u.MINUS_ASSIGN,u.STAR_ASSIGN,u.SLASH_ASSIGN,u.PERCENT_ASSIGN,u.CARET_ASSIGN)){let i=e.advance(),a=Z(e,t);if(n.type!=="variable"&&n.type!=="field"&&n.type!=="array_access")throw new Error("Invalid assignment target");return{type:"assignment",operator:{"=":"=","+=":"+=","-=":"-=","*=":"*=","/=":"/=","%=":"%=","^=":"^="}[i.value],target:n,value:a}}return n}function It(e){let t=0,n=e.pos;for(;n<e.tokens.length;){let i=e.tokens[n];if(i.type===u.LPAREN&&t++,i.type===u.RPAREN&&t--,i.type===u.QUESTION&&t===0)return!0;if(i.type===u.NEWLINE||i.type===u.SEMICOLON||i.type===u.RBRACE||i.type===u.COMMA||i.type===u.PIPE)return!1;n++}return!1}function wt(e){let t=Se(e);for(;e.check(u.OR);){e.advance();let n=Se(e);t={type:"binary",operator:"||",left:t,right:n}}return t}function Se(e){let t=ye(e);for(;e.check(u.AND);){e.advance();let n=ye(e);t={type:"binary",operator:"&&",left:t,right:n}}return t}function ye(e){let t=mt(e);if(e.check(u.IN)){e.advance();let n=String(e.expect(u.IDENT).value);return{type:"in",key:t,array:n}}return t}function mt(e){let t=Re(e);for(;vt(e)&&!gt(e);){let n=Re(e);t={type:"binary",operator:" ",left:t,right:n}}return t}function Re(e){let t=Ae(e);for(;e.match(u.MATCH,u.NOT_MATCH);){let n=e.advance().type===u.MATCH?"~":"!~",i=Ae(e);t={type:"binary",operator:n,left:t,right:i}}return t}function Ae(e){let t=e.parseAddSub();for(;e.match(u.LT,u.LE,u.GE,u.EQ,u.NE);){let n=e.advance(),i=e.parseAddSub();t={type:"binary",operator:{"<":"<","<=":"<=",">=":">=","==":"==","!=":"!="}[n.value],left:t,right:i}}return t}function vt(e){return e.match(u.NUMBER,u.STRING,u.IDENT,u.DOLLAR,u.LPAREN,u.NOT,u.MINUS,u.PLUS,u.INCREMENT,u.DECREMENT)}function gt(e){return e.match(u.AND,u.OR,u.QUESTION,u.ASSIGN,u.PLUS_ASSIGN,u.MINUS_ASSIGN,u.STAR_ASSIGN,u.SLASH_ASSIGN,u.PERCENT_ASSIGN,u.CARET_ASSIGN,u.COMMA,u.SEMICOLON,u.NEWLINE,u.RBRACE,u.RPAREN,u.RBRACKET,u.COLON,u.PIPE,u.APPEND,u.GT,u.IN)}function we(e){e.expect(u.PRINTF);let t=e.check(u.LPAREN);t&&(e.advance(),e.skipNewlines());let n=t?e.parseExpression():W(e),i=[];for(;e.check(u.COMMA);)e.advance(),t&&e.skipNewlines(),i.push(t?e.parseExpression():W(e));t&&(e.skipNewlines(),e.expect(u.RPAREN));let a;return e.check(u.GT)?(e.advance(),a={redirect:">",file:e.parsePrimary()}):e.check(u.APPEND)&&(e.advance(),a={redirect:">>",file:e.parsePrimary()}),{type:"printf",format:n,args:i,output:a}}var V=class{tokens=[];pos=0;parse(t){let n=new $(t);return this.tokens=n.tokenize(),this.pos=0,this.parseProgram()}setPos(t){this.pos=t}current(){return this.tokens[this.pos]||{type:r.EOF,value:"",line:0,column:0}}advance(){let t=this.current();return this.pos<this.tokens.length&&this.pos++,t}match(...t){return t.includes(this.current().type)}check(t){return this.current().type===t}expect(t,n){if(!this.check(t)){let i=this.current();throw new Error(n||`Expected ${t}, got ${i.type} at line ${i.line}:${i.column}`)}return this.advance()}skipNewlines(){for(;this.check(r.NEWLINE);)this.advance()}skipTerminators(){for(;this.check(r.NEWLINE)||this.check(r.SEMICOLON);)this.advance()}parseProgram(){let t=[],n=[];for(this.skipNewlines();!this.check(r.EOF)&&(this.skipNewlines(),!this.check(r.EOF));)this.check(r.FUNCTION)?t.push(this.parseFunction()):n.push(this.parseRule()),this.skipTerminators();return{functions:t,rules:n}}parseFunction(){this.expect(r.FUNCTION);let t=this.expect(r.IDENT).value;this.expect(r.LPAREN);let n=[];if(!this.check(r.RPAREN))for(n.push(this.expect(r.IDENT).value);this.check(r.COMMA);)this.advance(),n.push(this.expect(r.IDENT).value);this.expect(r.RPAREN),this.skipNewlines();let i=this.parseBlock();return{name:t,params:n,body:i}}parseRule(){let t;if(this.check(r.BEGIN))this.advance(),t={type:"begin"};else if(this.check(r.END))this.advance(),t={type:"end"};else if(this.check(r.LBRACE))t=void 0;else if(this.check(r.REGEX)){let i=this.advance();if(this.check(r.AND)||this.check(r.OR)){let a={type:"binary",operator:"~",left:{type:"field",index:{type:"number",value:0}},right:{type:"regex",pattern:i.value}};t={type:"expr_pattern",expression:this.parseLogicalOrRest(a)}}else{let a={type:"regex_pattern",pattern:i.value};if(this.check(r.COMMA)){this.advance();let s;this.check(r.REGEX)?s={type:"regex_pattern",pattern:this.advance().value}:s={type:"expr_pattern",expression:this.parseExpression()},t={type:"range",start:a,end:s}}else t=a}}else{let a={type:"expr_pattern",expression:this.parseExpression()};if(this.check(r.COMMA)){this.advance();let s;this.check(r.REGEX)?s={type:"regex_pattern",pattern:this.advance().value}:s={type:"expr_pattern",expression:this.parseExpression()},t={type:"range",start:a,end:s}}else t=a}this.skipNewlines();let n;return this.check(r.LBRACE)?n=this.parseBlock():n={type:"block",statements:[{type:"print",args:[{type:"field",index:{type:"number",value:0}}]}]},{pattern:t,action:n}}parseBlock(){this.expect(r.LBRACE),this.skipNewlines();let t=[];for(;!this.check(r.RBRACE)&&!this.check(r.EOF);)t.push(this.parseStatement()),this.skipTerminators();return this.expect(r.RBRACE),{type:"block",statements:t}}parseStatement(){if(this.check(r.SEMICOLON)||this.check(r.NEWLINE))return this.advance(),{type:"block",statements:[]};if(this.check(r.LBRACE))return this.parseBlock();if(this.check(r.IF))return this.parseIf();if(this.check(r.WHILE))return this.parseWhile();if(this.check(r.DO))return this.parseDoWhile();if(this.check(r.FOR))return this.parseFor();if(this.check(r.BREAK))return this.advance(),{type:"break"};if(this.check(r.CONTINUE))return this.advance(),{type:"continue"};if(this.check(r.NEXT))return this.advance(),{type:"next"};if(this.check(r.NEXTFILE))return this.advance(),{type:"nextfile"};if(this.check(r.EXIT)){this.advance();let n;return!this.check(r.NEWLINE)&&!this.check(r.SEMICOLON)&&!this.check(r.RBRACE)&&!this.check(r.EOF)&&(n=this.parseExpression()),{type:"exit",code:n}}if(this.check(r.RETURN)){this.advance();let n;return!this.check(r.NEWLINE)&&!this.check(r.SEMICOLON)&&!this.check(r.RBRACE)&&!this.check(r.EOF)&&(n=this.parseExpression()),{type:"return",value:n}}if(this.check(r.DELETE)){this.advance();let n=this.parsePrimary();if(n.type!=="array_access"&&n.type!=="variable")throw new Error("delete requires array element or array");return{type:"delete",target:n}}return this.check(r.PRINT)?Ie(this):this.check(r.PRINTF)?we(this):{type:"expr_stmt",expression:this.parseExpression()}}parseIf(){this.expect(r.IF),this.expect(r.LPAREN);let t=this.parseExpression();this.expect(r.RPAREN),this.skipNewlines();let n=this.parseStatement();this.skipTerminators();let i;return this.check(r.ELSE)&&(this.advance(),this.skipNewlines(),i=this.parseStatement()),{type:"if",condition:t,consequent:n,alternate:i}}parseWhile(){this.expect(r.WHILE),this.expect(r.LPAREN);let t=this.parseExpression();this.expect(r.RPAREN),this.skipNewlines();let n=this.parseStatement();return{type:"while",condition:t,body:n}}parseDoWhile(){this.expect(r.DO),this.skipNewlines();let t=this.parseStatement();this.skipNewlines(),this.expect(r.WHILE),this.expect(r.LPAREN);let n=this.parseExpression();return this.expect(r.RPAREN),{type:"do_while",body:t,condition:n}}parseFor(){if(this.expect(r.FOR),this.expect(r.LPAREN),this.check(r.IDENT)){let s=this.advance();if(this.check(r.IN)){this.advance();let o=this.expect(r.IDENT).value;this.expect(r.RPAREN),this.skipNewlines();let l=this.parseStatement();return{type:"for_in",variable:s.value,array:o,body:l}}this.pos--}let t;this.check(r.SEMICOLON)||(t=this.parseExpression()),this.expect(r.SEMICOLON);let n;this.check(r.SEMICOLON)||(n=this.parseExpression()),this.expect(r.SEMICOLON);let i;this.check(r.RPAREN)||(i=this.parseExpression()),this.expect(r.RPAREN),this.skipNewlines();let a=this.parseStatement();return{type:"for",init:t,condition:n,update:i,body:a}}parseExpression(){return this.parseAssignment()}parseAssignment(){let t=this.parseTernary();if(this.match(r.ASSIGN,r.PLUS_ASSIGN,r.MINUS_ASSIGN,r.STAR_ASSIGN,r.SLASH_ASSIGN,r.PERCENT_ASSIGN,r.CARET_ASSIGN)){let n=this.advance(),i=this.parseAssignment();if(t.type!=="variable"&&t.type!=="field"&&t.type!=="array_access")throw new Error("Invalid assignment target");return{type:"assignment",operator:{"=":"=","+=":"+=","-=":"-=","*=":"*=","/=":"/=","%=":"%=","^=":"^="}[n.value],target:t,value:i}}return t}parseTernary(){let t=this.parsePipeGetline();if(this.check(r.QUESTION)){this.advance();let n=this.parseExpression();this.expect(r.COLON);let i=this.parseExpression();t={type:"ternary",condition:t,consequent:n,alternate:i}}return t}parsePipeGetline(){let t=this.parseOr();if(this.check(r.PIPE)){if(this.advance(),!this.check(r.GETLINE))throw new Error("Expected 'getline' after '|' in expression context");this.advance();let n;return this.check(r.IDENT)&&(n=this.advance().value),{type:"getline",command:t,variable:n}}return t}parseOr(){let t=this.parseAnd();for(;this.check(r.OR);){this.advance();let n=this.parseAnd();t={type:"binary",operator:"||",left:t,right:n}}return t}parseLogicalOrRest(t){for(t=this.parseLogicalAndRest(t);this.check(r.OR);){this.advance();let n=this.parseAnd();t={type:"binary",operator:"||",left:t,right:n}}return t}parseLogicalAndRest(t){for(;this.check(r.AND);){this.advance();let n=this.parseIn();t={type:"binary",operator:"&&",left:t,right:n}}return t}parseAnd(){let t=this.parseIn();for(;this.check(r.AND);){this.advance();let n=this.parseIn();t={type:"binary",operator:"&&",left:t,right:n}}return t}parseIn(){let t=this.parseConcatenation();if(this.check(r.IN)){this.advance();let n=this.expect(r.IDENT).value;return{type:"in",key:t,array:n}}return t}parseConcatenation(){let t=this.parseMatch();for(;this.canStartExpression()&&!this.isConcatTerminator();){let n=this.parseMatch();t={type:"binary",operator:" ",left:t,right:n}}return t}parseMatch(){let t=this.parseComparison();for(;this.match(r.MATCH,r.NOT_MATCH);){let n=this.advance().type===r.MATCH?"~":"!~",i=this.parseComparison();t={type:"binary",operator:n,left:t,right:i}}return t}parseComparison(){let t=this.parseAddSub();for(;this.match(r.LT,r.LE,r.GT,r.GE,r.EQ,r.NE);){let n=this.advance(),i=this.parseAddSub();t={type:"binary",operator:{"<":"<","<=":"<=",">":">",">=":">=","==":"==","!=":"!="}[n.value],left:t,right:i}}return t}canStartExpression(){return this.match(r.NUMBER,r.STRING,r.IDENT,r.DOLLAR,r.LPAREN,r.NOT,r.MINUS,r.PLUS,r.INCREMENT,r.DECREMENT)}isConcatTerminator(){return this.match(r.AND,r.OR,r.QUESTION,r.ASSIGN,r.PLUS_ASSIGN,r.MINUS_ASSIGN,r.STAR_ASSIGN,r.SLASH_ASSIGN,r.PERCENT_ASSIGN,r.CARET_ASSIGN,r.COMMA,r.SEMICOLON,r.NEWLINE,r.RBRACE,r.RPAREN,r.RBRACKET,r.COLON,r.PIPE,r.APPEND,r.IN)}parseAddSub(){let t=this.parseMulDiv();for(;this.match(r.PLUS,r.MINUS);){let n=this.advance().value,i=this.parseMulDiv();t={type:"binary",operator:n,left:t,right:i}}return t}parseMulDiv(){let t=this.parseUnary();for(;this.match(r.STAR,r.SLASH,r.PERCENT);){let n=this.advance(),i=this.parseUnary();t={type:"binary",operator:{"*":"*","/":"/","%":"%"}[n.value],left:t,right:i}}return t}parseUnary(){if(this.check(r.INCREMENT)){this.advance();let t=this.parseUnary();return t.type!=="variable"&&t.type!=="field"&&t.type!=="array_access"?{type:"unary",operator:"+",operand:{type:"unary",operator:"+",operand:t}}:{type:"pre_increment",operand:t}}if(this.check(r.DECREMENT)){this.advance();let t=this.parseUnary();return t.type!=="variable"&&t.type!=="field"&&t.type!=="array_access"?{type:"unary",operator:"-",operand:{type:"unary",operator:"-",operand:t}}:{type:"pre_decrement",operand:t}}if(this.match(r.NOT,r.MINUS,r.PLUS)){let t=this.advance().value,n=this.parseUnary();return{type:"unary",operator:t,operand:n}}return this.parsePower()}parsePower(){let t=this.parsePostfix();if(this.check(r.CARET)){this.advance();let n=this.parsePower();t={type:"binary",operator:"^",left:t,right:n}}return t}parsePostfix(){let t=this.parsePrimary();if(this.check(r.INCREMENT)){if(this.advance(),t.type!=="variable"&&t.type!=="field"&&t.type!=="array_access")throw new Error("Invalid increment operand");return{type:"post_increment",operand:t}}if(this.check(r.DECREMENT)){if(this.advance(),t.type!=="variable"&&t.type!=="field"&&t.type!=="array_access")throw new Error("Invalid decrement operand");return{type:"post_decrement",operand:t}}return t}parseFieldIndex(){if(this.check(r.INCREMENT)){this.advance();let t=this.parseFieldIndex();return t.type!=="variable"&&t.type!=="field"&&t.type!=="array_access"?{type:"unary",operator:"+",operand:{type:"unary",operator:"+",operand:t}}:{type:"pre_increment",operand:t}}if(this.check(r.DECREMENT)){this.advance();let t=this.parseFieldIndex();return t.type!=="variable"&&t.type!=="field"&&t.type!=="array_access"?{type:"unary",operator:"-",operand:{type:"unary",operator:"-",operand:t}}:{type:"pre_decrement",operand:t}}if(this.match(r.NOT,r.MINUS,r.PLUS)){let t=this.advance().value,n=this.parseFieldIndex();return{type:"unary",operator:t,operand:n}}return this.parseFieldIndexPower()}parseFieldIndexPower(){let t=this.parseFieldIndexPrimary();if(this.check(r.CARET)){this.advance();let n=this.parseFieldIndexPower();t={type:"binary",operator:"^",left:t,right:n}}return t}parseFieldIndexPrimary(){if(this.check(r.NUMBER))return{type:"number",value:this.advance().value};if(this.check(r.STRING))return{type:"string",value:this.advance().value};if(this.check(r.DOLLAR))return this.advance(),{type:"field",index:this.parseFieldIndex()};if(this.check(r.LPAREN)){this.advance();let t=this.parseExpression();return this.expect(r.RPAREN),t}if(this.check(r.IDENT)){let t=this.advance().value;if(this.check(r.LPAREN)){this.advance();let n=[];if(!this.check(r.RPAREN))for(n.push(this.parseExpression());this.check(r.COMMA);)this.advance(),n.push(this.parseExpression());return this.expect(r.RPAREN),{type:"call",name:t,args:n}}if(this.check(r.LBRACKET)){this.advance();let n=this.parseExpression();if(this.check(r.COMMA)){let i=[n];for(;this.check(r.COMMA);)this.advance(),i.push(this.parseExpression());this.expect(r.RBRACKET);let a=i.reduce((s,o)=>({type:"binary",operator:" ",left:{type:"binary",operator:" ",left:s,right:{type:"variable",name:"SUBSEP"}},right:o}));return{type:"array_access",array:t,key:a}}return this.expect(r.RBRACKET),{type:"array_access",array:t,key:n}}return{type:"variable",name:t}}throw new Error(`Unexpected token in field index: ${this.current().type} at line ${this.current().line}:${this.current().column}`)}parsePrimary(){if(this.check(r.NUMBER))return{type:"number",value:this.advance().value};if(this.check(r.STRING))return{type:"string",value:this.advance().value};if(this.check(r.REGEX))return{type:"regex",pattern:this.advance().value};if(this.check(r.DOLLAR))return this.advance(),{type:"field",index:this.parseFieldIndex()};if(this.check(r.LPAREN)){this.advance();let t=this.parseExpression();if(this.check(r.COMMA)){let n=[t];for(;this.check(r.COMMA);)this.advance(),n.push(this.parseExpression());return this.expect(r.RPAREN),{type:"tuple",elements:n}}return this.expect(r.RPAREN),t}if(this.check(r.GETLINE)){this.advance();let t,n;return this.check(r.IDENT)&&(t=this.advance().value),this.check(r.LT)&&(this.advance(),n=this.parsePrimary()),{type:"getline",variable:t,file:n}}if(this.check(r.IDENT)){let t=this.advance().value;if(this.check(r.LPAREN)){this.advance();let n=[];if(this.skipNewlines(),!this.check(r.RPAREN))for(n.push(this.parseExpression());this.check(r.COMMA);)this.advance(),this.skipNewlines(),n.push(this.parseExpression());return this.skipNewlines(),this.expect(r.RPAREN),{type:"call",name:t,args:n}}if(this.check(r.LBRACKET)){this.advance();let n=[this.parseExpression()];for(;this.check(r.COMMA);)this.advance(),n.push(this.parseExpression());this.expect(r.RBRACKET);let i;if(n.length===1)i=n[0];else{i=n[0];for(let a=1;a<n.length;a++)i={type:"binary",operator:" ",left:{type:"binary",operator:" ",left:i,right:{type:"variable",name:"SUBSEP"}},right:n[a]}}return{type:"array_access",array:t,key:i}}return{type:"variable",name:t}}throw new Error(`Unexpected token: ${this.current().type} at line ${this.current().line}:${this.current().column}`)}};var kt={name:"awk",summary:"pattern scanning and text processing language",usage:"awk [OPTIONS] 'PROGRAM' [FILE...]",options:["-F FS use FS as field separator","-v VAR=VAL assign VAL to variable VAR"," --help display this help and exit"]},fn={name:"awk",async execute(e,t){if(ne(e))return te(kt);let n=/\s+/,i=" ",a={},s=0;for(let c=0;c<e.length;c++){let p=e[c];if(p==="-F"&&c+1<e.length)i=Y(e[++c]),n=me(i),s=c+1;else if(p.startsWith("-F"))i=Y(p.slice(2)),n=me(i),s=c+1;else if(p==="-v"&&c+1<e.length){let E=e[++c],d=E.indexOf("=");if(d>0){let y=E.slice(0,d),L=Y(E.slice(d+1));a[y]=L}s=c+1}else{if(p.startsWith("--"))return X("awk",p);if(p.startsWith("-")&&p.length>1){let E=p[1];if(E!=="F"&&E!=="v")return X("awk",`-${E}`);s=c+1}else if(!p.startsWith("-")){s=c;break}}}if(s>=e.length)return{stdout:"",stderr:`awk: missing program
15
- `,exitCode:1};let o=e[s],l=e.slice(s+1),h=new V,N;try{N=h.parse(o)}catch(c){return{stdout:"",stderr:`awk: ${c instanceof Error?c.message:String(c)}
16
- `,exitCode:1}}let v={readFile:t.fs.readFile.bind(t.fs),writeFile:t.fs.writeFile.bind(t.fs),appendFile:async(c,p)=>{try{let E=await t.fs.readFile(c);await t.fs.writeFile(c,E+p)}catch{await t.fs.writeFile(c,p)}},resolvePath:t.fs.resolvePath.bind(t.fs)},R=K({fieldSep:n,maxIterations:t.limits?.maxAwkIterations,fs:v,cwd:t.cwd,exec:t.exec?c=>t.exec(c,{cwd:t.cwd}):void 0});R.FS=i,R.vars={...a},R.ARGC=l.length+1,R.ARGV={0:"awk"};for(let c=0;c<l.length;c++)R.ARGV[String(c+1)]=l[c];R.ENVIRON={...t.env};let I=new _(R);I.execute(N);let ee=N.rules.some(c=>c.pattern?.type!=="begin"&&c.pattern?.type!=="end"),w=N.rules.some(c=>c.pattern?.type==="end");try{if(await I.executeBegin(),R.shouldExit)return await I.executeEnd(),{stdout:I.getOutput(),stderr:"",exitCode:I.getExitCode()};if(!ee&&!w)return{stdout:I.getOutput(),stderr:"",exitCode:I.getExitCode()};let c=[];if(l.length>0)for(let p of l)try{let E=t.fs.resolvePath(t.cwd,p),y=(await t.fs.readFile(E)).split(`
17
- `);y.length>0&&y[y.length-1]===""&&y.pop(),c.push({filename:p,lines:y})}catch{return{stdout:"",stderr:`awk: ${p}: No such file or directory
18
- `,exitCode:1}}else{let p=t.stdin.split(`
19
- `);p.length>0&&p[p.length-1]===""&&p.pop(),c.push({filename:"",lines:p})}for(let p of c){for(R.FILENAME=p.filename,R.FNR=0,R.lines=p.lines,R.lineIndex=-1,R.shouldNextFile=!1;R.lineIndex<p.lines.length-1&&(R.lineIndex++,await I.executeLine(p.lines[R.lineIndex]),!(R.shouldExit||R.shouldNextFile)););if(R.shouldExit)break}return await I.executeEnd(),{stdout:I.getOutput(),stderr:"",exitCode:I.getExitCode()}}catch(c){let p=c instanceof Error?c.message:String(c),E=c instanceof C?C.EXIT_CODE:2;return{stdout:I.getOutput(),stderr:`awk: ${p}
20
- `,exitCode:E}}}};function Y(e){return e.replace(/\\t/g," ").replace(/\\n/g,`
21
- `).replace(/\\r/g,"\r").replace(/\\b/g,"\b").replace(/\\f/g,"\f").replace(/\\a/g,"\x07").replace(/\\v/g,"\v").replace(/\\\\/g,"\\")}function me(e){if(e===" ")return/\s+/;if(/[[\](){}.*+?^$|\\]/.test(e))try{return new RegExp(e)}catch{return new RegExp(ve(e))}return new RegExp(ve(e))}function ve(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}export{fn as awkCommand2};
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env node
2
- import{a as h,b as d}from"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";var l={name:"bash",summary:"execute shell commands or scripts",usage:"bash [OPTIONS] [SCRIPT_FILE] [ARGUMENTS...]",options:["-c COMMAND execute COMMAND string"," --help display this help and exit"],notes:["Without -c, reads and executes commands from SCRIPT_FILE.","Arguments are passed as $1, $2, etc. to the script.",'$0 is set to the script name (or "bash" with -c).']},f={name:"bash",async execute(e,t){if(d(e))return h(l);if(e[0]==="-c"&&e.length>=2){let r=e[1],s=e[2]||"bash",c=e.slice(3);return i(r,s,c,t)}if(e.length===0)return t.stdin?.trim()?i(t.stdin,"bash",[],t):{stdout:"",stderr:"",exitCode:0};let n=e[0],o=e.slice(1);try{let r=t.fs.resolvePath(t.cwd,n),s=await t.fs.readFile(r);return i(s,n,o,t)}catch{return{stdout:"",stderr:`bash: ${n}: No such file or directory
3
- `,exitCode:127}}}},p={name:"sh",async execute(e,t){if(d(e))return h({...l,name:"sh",summary:"execute shell commands or scripts (POSIX shell)"});if(e[0]==="-c"&&e.length>=2){let r=e[1],s=e[2]||"sh",c=e.slice(3);return i(r,s,c,t)}if(e.length===0)return t.stdin?.trim()?i(t.stdin,"sh",[],t):{stdout:"",stderr:"",exitCode:0};let n=e[0],o=e.slice(1);try{let r=t.fs.resolvePath(t.cwd,n),s=await t.fs.readFile(r);return i(s,n,o,t)}catch{return{stdout:"",stderr:`sh: ${n}: No such file or directory
4
- `,exitCode:127}}}};async function i(e,t,n,o){if(!o.exec)return{stdout:"",stderr:`bash: internal error: exec function not available
5
- `,exitCode:1};let r={...o.exportedEnv||{},0:t,"#":String(n.length),"@":n.join(" "),"*":n.join(" ")};n.forEach((a,u)=>{r[String(u+1)]=a});let s=e;if(s.startsWith("#!")){let a=s.indexOf(`
6
- `);a!==-1&&(s=s.slice(a+1))}return await o.exec(s,{env:r,cwd:o.cwd})}export{f as bashCommand,p as shCommand};