troubleshooting Part 1

commandline session

$ 4.2.20 5 176---> cat program.sh
#!/bin/bash
# trouble: script to demonstrate common errors
number=1
if [ $number = 1 ]; then
echo "Number is equal to 1."
else
echo "Number is not equal to 1."
fi
$ 4.2.20 6 177---> sh program.sh
Number is equal to 1.
$ 4.2.20 7 178--->

Missing Quotes

$ 4.2.20 8 179---> cat program.sh
#!/bin/bash
# trouble: script to demonstrate common errors
number=1
if [ $number = 1 ]; then
echo "Number is equal to 1.
else
echo "Number is not equal to 1."
fi
$ 4.2.20 9 180---> sh program.sh
program.sh: 9: program.sh: Syntax error: Unterminated quoted string
$ 4.2.20 10 181--->

Missing or Unexpected Tokens

$ 4.2.20 11 182---> cat program.sh
#!/bin/bash
# trouble: script to demonstrate common errors
number=1
if [ $number = 1 ] then
echo "Number is equal to 1."
else
echo "Number is not equal to 1."
fi
$ 4.2.20 12 183---> sh program.sh
program.sh: 6: program.sh: Syntax error: "else" unexpected (expecting "then")
$ 4.2.20 13 184--->

Unanticipated Expansions

$ 4.2.20 14 185---> cat program.sh
#!/bin/bash
# trouble: script to demonstrate common errors
number=
if [ $number = 1 ]; then
echo "Number is equal to 1."
else
echo "Number is not equal to 1."
fi
$ 4.2.20 15 186---> sh program.sh
program.sh: 4: [: =: unexpected operator
Number is not equal to 1.
$ 4.2.20 16 187--->

Note
Token (parser), usually a word or other atomic parse element.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s