#!/usr/bin/env node
import{c as d}from"./chunk-4PRVMER6.js";import{a as h,b as l}from"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";var u={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).']},C={name:"bash",async execute(e,t){if(l(e))return h(u);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
`,exitCode:127}}}},b={name:"sh",async execute(e,t){if(l(e))return h({...u,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
`,exitCode:127}}}};async function i(e,t,n,o){if(!o.exec)return{stdout:"",stderr:`bash: internal error: exec function not available
`,exitCode:1};let r=d(o.exportedEnv||{},{0:t,"#":String(n.length),"@":n.join(" "),"*":n.join(" ")});n.forEach((a,m)=>{r[String(m+1)]=a});let s=e;if(s.startsWith("#!")){let a=s.indexOf(`
`);a!==-1&&(s=s.slice(a+1))}return await o.exec(s,{env:r,cwd:o.cwd})}export{C as bashCommand,b as shCommand};
