When a script fails, bash says where and why, in one line:
./open.sh:the scriptline 3:the lineecoh:the wordcommand not foundthe problem
Fix the first error, then run it again.
| Error | Fix |
|---|---|
Permission denied | chmod u+x FILE |
WORD: command not found | Fix the typo |
syntax error: unexpected end of file | Close the if with fi, or the loop with done |
[: =: unary operator expected | Quote the variable: "$var" |
too many arguments | Quote the variable: "$var" |
When there is no error
bash -x FILE ARGS runs a script and shows each command, with its values filled in, after a +:
text
learner@reef:~$ bash -x order-total.sh 4 3
+ qty=4
+ price=3
+ total=0 ← 4 × 3 is not 0: this line is wrong
+ echo 'total: 0'
total: 0That line was total=$(( qty * prise )): a typo, and an unset name counts as 0.
- Run
./hours.sh north. Fix the first error innano ~/hours.sh, and run it again, until it shows the north shop. - Run
./hours.sh, then./hours.sh "east side", and fix the error. - Run
./tip-split.sh 60 10 3: it should say 66, and 22 each. Trace it withbash -x tip-split.sh 60 10 3, and fix the first wrong line.
Objectives
./hours.sh northshows the north shop.- It works with no shop, and for
east side. tip-split.shprints the right total.