Help with Check Syntax of Shell Script without Running

Hi Everyone,

Is there any way ( generic) to check syntax of Shell Scripts without running it??

Assuming you're using a shell based on Bourne shell syntax (such as ksh or bash ), try:

YourShell -n YourScriptPath

Don's suggestion is the best bet. You can also try adding a line like this at the top

set -n

in the script itself. For modern shells - NOT csh.

Thanks for the help... I tried sh -n <script-name> it worked fine for some errors...

But in case of the following errors, nothing happened
Example:-

1)

export FILE1=INPUT-FILE
export FILE2=OUT-FILE
cp FILE1 $FILE2

Here $ should be there before FILE1.
This error is not caught

2) If a file which is declared, is not at all present in the path mentioned, those errors are not handled

3) # is not present in the starting of comment line...this error is not being caught.

Is there any way to take care of the above??

In the thread title you talk about syntax errors and those are checked with the -n flag.
Your examples 1) and 2) are semantic errors but syntactically correct.
1) copying a file called FILE1 is syntactially valid, no matter wheter you have defined a variable with the same name or not.
2) what do you mean when you say "a file which is declared"? Anyway, a file can be created any time. It is no syntax error just because a file referenced any way is not there at the time you check the syntax.
3) may be a special case of 2). The comment may be interpreted as an executeable with arguments (which does not have to exist at the time you check).