0

I have my bash code.

#!/bin/bash

read message
echo $message | tr "A-Za-z" "N-ZA-Mn-za-m"
if [ $message == false ]; then
fi
done

It works but I get syntax errors after,

rot13.sh: line 6: syntax error near unexpected token `fi'
rot13.sh: line 6: `fi'

Now I don't expect a solution in this thread but I'm just wondering where should I go and that should I do when I get these errors? Is there any commands I can use in the compiler or documentation/checklists that check for syntax errors.

I am new to bash code so being able to check and understand there syntax error would help a lot.

Thank you.

2
  • 4
    Please take a look: shellcheck.net Commented Mar 18, 2018 at 15:14
  • 1
    Are you expecting your second line to modify the value of $message? (Spoiler: it doesn't.) Commented Mar 18, 2018 at 15:19

1 Answer 1

2
#!/bin/bash

read message
echo "$message" | tr "A-Za-z" "N-ZA-Mn-za-m"
if [ "$message" = false ]; then
    echo 'false'
fi

You need something between then and fi.

Before asking human help, always test your code on http://www.shellcheck.net/ before

And if you need to store the output of the tr command :

message="$(echo "$message" | tr "A-Za-z" "N-ZA-Mn-za-m")"

Last thing, you have a lost done statement at the end of the script

Sign up to request clarification or add additional context in comments.

2 Comments

A lot of questions would be self replied if people know about shellcheck.
Yes, and the answers too; there is a trailing done in the script. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.