Troubleshooting of bash script

From LemonWiki共筆
Revision as of 13:49, 20 January 2025 by Planetoid (talk | contribs) (→‎How to fix Line Ending Compatibility Error)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Resolving Common Bash Script Execution Errors

Common Bash Script Execution Errors

How to fix Permission Denied Error: "unable to execute"

Error description:

$ ./bash-script.sh
unable to execute ./bash-script.sh: No such file or directory

Resolution: Add execute permissions to the script using:

$ chmod +x bash-script.sh

How to fix Line Ending Compatibility Error

Problem:

$ ./bash-script.sh
-bash: ./bash-script.sh: /bin/bash^M: bad interpreter: No such file or directory

Resolution: Convert Windows line endings (CRLF) to Unix format (LF):

$ sed -i 's/\r$//' bash-script.sh

This error typically occurs when a script is created on Windows and transferred to a Unix/Linux system. The sed command removes the Windows carriage return characters (\r) that cause the interpreter error.