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.

Ankit Zalani
  • 335
  • 1
  • 3
  • 8

2 Answers2

30
bash -n scriptname

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

user.dz
  • 48,105
Bodo
  • 552
  • 2
  • 7
  • 13
5

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

girardengo
  • 4,965
  • 1
  • 26
  • 31