create_bash_script
Generate and save a bash script file with custom content, specifying the path and optionally making it executable. Ideal for automating tasks in Linux environments via the Linux Bash MCP Server.
Instructions
Create a bash script file with specified content
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content | Yes | Content of the bash script | |
| executable | No | Make the script executable (optional, defaults to true) | |
| scriptPath | Yes | Path where to create the script file |
Implementation Reference
- src/index.js:448-512 (handler)The handler function that implements the create_bash_script tool. It writes the provided content to the specified scriptPath in the WSL Linux environment and optionally makes it executable using chmod.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:214-236 (registration)Registration of the create_bash_script tool in the list of tools, including its 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:217-234 (schema)Input schema definition for the create_bash_script tool.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 (handler)Dispatch to the createBashScript handler in the tool request switch statement.case "create_bash_script": return await this.createBashScript(args);