21

I have a long shell script containing a lot of conditions and I want to know whether there is any syntax error in the script without running it.

Since shell script is interpreted I think it is not possible but is there a way to know by using some trick.

29
bash -n scriptname

Although, this will check syntax, not command availability. (will not warn if script uses a command that is not installed yet)

  • 3
    In addition to bash's inbuilt syntax checḱing you can use shellcheck to identify less severe issues and bad practices. – Glutanimate Jun 15 '14 at 22:40
4

I found an online tool to check the syntax of the script. In addition to checking the script, also suggests possible corrections to avoid errors.

Check shell script online

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.