{"record":{"id":"87f7338079b22718","repo":"HMCL-dev/HMCL","slug":"the-extension-of-is-not-sh-bash-ps1-or-c","errorCode":null,"errorMessage":"The extension of  is not 'sh', 'bash', 'ps1' or 'command' in macOS/Linux","messagePattern":"The extension of  is not 'sh', 'bash', 'ps1' or 'command' in macOS/Linux","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"HMCLCore/src/main/java/org/jackhuang/hmcl/launch/DefaultLauncher.java","lineNumber":873,"sourceCode":"            classpath.add(FileUtils.getAbsolutePath(selectedOptiFineInstallerFile));\n        }\n        return classpath;\n    }\n\n    @Override\n    public void makeLaunchScript(Path scriptFile) throws IOException {\n        boolean isWindows = OperatingSystem.WINDOWS == OperatingSystem.CURRENT_OS;\n\n        Path nativeFolder = getNativeFolder();\n\n        String scriptExtension = FileUtils.getExtension(scriptFile);\n        boolean usePowerShell = \"ps1\".equals(scriptExtension);\n\n        if (!usePowerShell) {\n            if (isWindows && !scriptExtension.equalsIgnoreCase(\"bat\"))\n                throw new IllegalArgumentException(\"The extension of \" + scriptFile + \" is not 'bat' or 'ps1' in Windows\");\n            else if (!isWindows && !(scriptExtension.equalsIgnoreCase(\"sh\") || scriptExtension.equalsIgnoreCase(\"command\") || scriptExtension.equalsIgnoreCase(\"bash\")))\n                throw new IllegalArgumentException(\"The extension of \" + scriptFile + \" is not 'sh', 'bash', 'ps1' or 'command' in macOS/Linux\");\n        }\n\n        final Command commandLine = generateCommandLine(nativeFolder);\n        final String command = usePowerShell ? null : commandLine.commandLine.toString();\n        Map<String, String> envVars = getEnvVars(nativeFolder);\n\n        if (isWindows && !usePowerShell) {\n            // https://stackoverflow.com/a/28452546\n            // https://learn.microsoft.com/troubleshoot/windows-client/shell-experience/command-line-string-limitation\n            if (command.length() > 32767) {\n                throw new CommandTooLongException();\n            }\n        }\n\n        if (isUsingLog4j())\n            extractLog4jConfigurationFile();\n\n        if (!options.isUseCustomNatives())","sourceCodeStart":855,"sourceCodeEnd":891,"githubUrl":"https://github.com/HMCL-dev/HMCL/blob/24702dc5a0214034f4c27166d5fd30cad08cec19/HMCLCore/src/main/java/org/jackhuang/hmcl/launch/DefaultLauncher.java#L855-L891","documentation":"DefaultLauncher.makeLaunchScript requires that on macOS/Linux the script file extension be sh, bash, command, or ps1 (ps1 selects PowerShell output). It throws IllegalArgumentException(\"The extension of <file> is not 'sh', 'bash', 'ps1' or 'command' in macOS/Linux\") when the target file has another extension on a non-Windows host.","triggerScenarios":"Calling makeLaunchScript(scriptFile, ...) on Linux/macOS with a file whose extension is not one of sh/bash/command/ps1 — e.g. exporting game.bat or game.txt on a Linux machine.","commonSituations":"Copy-pasting a Windows-oriented export path (.bat) on Linux; text editors appending .txt; CI scripts generating scripts with a fixed .bat name regardless of OS.","solutions":["Use a .sh (or .bash/.command/.ps1) file name when exporting on macOS/Linux.","Rename the script file extension to .sh before calling makeLaunchScript.","Branch on the OS in your code to choose the correct extension, as the launcher itself does with isWindows.","Remember to chmod +x the generated .sh script afterwards to make it executable."],"exampleFix":"// before\n// launcher.makeLaunchScript(Path.of(\"game.bat\"), ...); // on Linux\n// after\n// launcher.makeLaunchScript(Path.of(\"game.sh\"), ...); // on Linux","handlingStrategy":"validation","validationCode":"String ext = FileUtils.getExtension(scriptFile);\nboolean isWindows = OS.WINDOWS == OperatingSystem.CURRENT_OS;\nif (!isWindows && !\"ps1\".equals(ext) && !(\"sh\".equalsIgnoreCase(ext) || \"bash\".equalsIgnoreCase(ext) || \"command\".equalsIgnoreCase(ext))) {\n    throw new IllegalArgumentException(\"Use .sh/.bash/.command/.ps1 on macOS/Linux, got: \" + ext);\n}","typeGuard":null,"tryCatchPattern":"try {\n    launcher.makeLaunchScript(scriptFile, ...);\n} catch (IllegalArgumentException e) {\n    // rename the script file to .sh (or .ps1) and retry\n}","preventionTips":["Never export .bat scripts on macOS/Linux; map to .sh instead","OS-branch extension selection in automation/CI scripts","chmod +x generated shell scripts after export"],"tags":["launcher","linux","macos","script","file-extension"],"backgroundTag":"invalid-argument-value","analyzedSha":"24702dc5a0214034f4c27166d5fd30cad08cec19","analyzedAt":"2026-09-10T12:36:46.680Z","contentChangedAt":"2026-09-10T12:36:46.680Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}