Troubleshooting of bash script

From LemonWiki共筆
Jump to navigation Jump to search

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.