Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 24 down vote accepted
bash -n scriptname

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

share|improve this answer
2  
In addition to bash's inbuilt syntax checḱing you can use shellcheck to identify less severe issues and bad practices. –  Glutanimate Jun 15 at 22:40

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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