A script that does not run usually fails at one of four steps. Check them in this order:
1. The shell must find it127 command not found: add its directory to PATH, or use the path
2. It must be allowed to run126 Permission denied: chmod u+x
3. The kernel must know the interpreterthe first line must be #!/bin/bash
4. The lines must worka missing variable: export it. A typing error: fix the line
The checklist
| You see | Check | Fix |
|---|---|---|
command not found, code 127 | echo $PATH, ls -l DIR | export PATH="DIR:$PATH", or run it by its path |
Permission denied, code 126 | ls -l FILE | chmod u+x FILE |
| A value from a variable is empty in the output | printenv NAME | export NAME=value |
bash: WORD: command not found while the script runs | cat the script, find WORD | Fix the typing error in the editor |
After each fix, run the script again and read the new result. Each fix takes you one step down the list, until the exit code is 0.