Troubleshooting of bash script: Difference between revisions
Jump to navigation
Jump to search
(Created page with "Resolving Common Bash Script Execution Errors __TOC__ == Common Bash Script Execution Errors == === How to fix Permission Denied Error: "unable to execute" === '''Error description:''' <pre> $ ./bash-script.sh unable to execute ./bash-script.sh: No such file or directory </pre> '''Resolution:''' Add execute permissions to the script using: <pre> $ chmod +x bash-script.sh </pre> === How to fix Line Ending Compatibility Error === '''Problem:''' <pre> $ ./bash-script.s...") |
|||
| Line 26: | Line 26: | ||
'''Resolution:''' | '''Resolution:''' | ||
Convert Windows line endings (CRLF) to Unix format (LF): | Convert Windows [[Return symbol | line endings]] (CRLF) to Unix format (LF): | ||
<pre> | <pre> | ||
$ sed -i 's/\r$//' bash-script.sh | $ sed -i 's/\r$//' bash-script.sh | ||
| Line 34: | Line 34: | ||
[[Category: Linux]] [[Category: Revised with LLMs]] | [[Category: Linux]] | ||
[[Category: Revised with LLMs]] | |||
Latest revision as of 13:49, 20 January 2025
Resolving Common Bash Script Execution Errors
Common Bash Script Execution Errors[edit]
How to fix Permission Denied Error: "unable to execute"[edit]
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[edit]
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.