create_bash_script
Generate bash script files with custom content and set execution permissions for automating Linux tasks in WSL2 environments on Windows.
Instructions
Create a bash script file with specified content
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| scriptPath | Yes | Path where to create the script file | |
| content | Yes | Content of the bash script | |
| executable | No | Make the script executable (optional, defaults to true) |
Implementation Reference
- src/index.js:448-511 (handler)The core handler function for the 'create_bash_script' tool. It validates inputs, escapes the script content, writes it to the specified path in the WSL Linux environment using 'echo > file', makes it executable if requested via 'chmod +x', and returns a JSON-formatted success or error response.async createBashScript(args) { const { scriptPath, content, executable = true } = args; if (!scriptPath || typeof scriptPath !== "string") { throw new Error("Script path is required and must be a string"); } if (!content || typeof content !== "string") { throw new Error("Script content is required and must be a string"); } if (!this.wslDistribution) { throw new Error("WSL distribution not configured"); } try { // Escape content for bash const escapedContent = content.replace(/'/g, "'\"'\"'"); // Create the script file const createCommand = `wsl -d ${this.wslDistribution} -- bash -c "echo '${escapedContent}' > '${scriptPath}'"`; console.error(`[DEBUG] Creating script: ${scriptPath}`); await execAsync(createCommand); // Make executable if requested if (executable) { const chmodCommand = `wsl -d ${this.wslDistribution} -- chmod +x '${scriptPath}'`; await execAsync(chmodCommand); } return { content: [ { type: "text", text: JSON.stringify({ success: true, scriptPath: scriptPath, executable: executable, wslDistribution: this.wslDistribution, message: "Script created successfully", timestamp: new Date().toISOString() }, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text", text: JSON.stringify({ success: false, scriptPath: scriptPath, wslDistribution: this.wslDistribution, error: error.message, timestamp: new Date().toISOString() }, null, 2), }, ], }; } }
- src/index.js:217-235 (schema)The input schema definition for the 'create_bash_script' tool, specifying required parameters (scriptPath, content) and optional executable flag.inputSchema: { type: "object", properties: { scriptPath: { type: "string", description: "Path where to create the script file", }, content: { type: "string", description: "Content of the bash script", }, executable: { type: "boolean", description: "Make the script executable (optional, defaults to true)", default: true } }, required: ["scriptPath", "content"], },
- src/index.js:214-236 (registration)The tool registration entry in the ListTools response, including name, description, and input schema.{ name: "create_bash_script", description: "Create a bash script file with specified content", inputSchema: { type: "object", properties: { scriptPath: { type: "string", description: "Path where to create the script file", }, content: { type: "string", description: "Content of the bash script", }, executable: { type: "boolean", description: "Make the script executable (optional, defaults to true)", default: true } }, required: ["scriptPath", "content"], }, },
- src/index.js:286-287 (registration)The dispatch case in the CallToolRequestHandler switch statement that routes calls to the createBashScript handler.case "create_bash_script": return await this.createBashScript(args);