Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.
$ cat foo.sh 
#!/bin/ksh

echo foo
ehco foo2

It doesn't warns for errors:

$ /bin/ksh -n foo.sh 
$ echo $?
0

Question: How can I get the "ksh -n" to warn me about syntax errors?

share|improve this question

2 Answers 2

up vote 0 down vote accepted

If you had syntax errors in that script, you'd see them on stderr. ksh -n is the right thing. An example:

$ cat script.ksh
touch tmpfile
for f in tmpfile   # missing "do"
  rm $f
done
$ ksh script.ksh
script.ksh: syntax error at line 3: `rm' unexpected
$ ls -l tmp*
-rw-rw-r-- 1 glennj glennj 0 Jul 22 06:54 tmpfile
$ rm tmpfile
$ ksh -n script.ksh
script.ksh: syntax error at line 3: `rm' unexpected
$ ls -l tmp*
ls: cannot access tmp*: No such file or directory

So, the script was parsed but not executed (the file was not created)

share|improve this answer

This is not a syntax error for actual ksh syntax, it's syntax error for invalid command name which only catched at run time. When you run it, you will get command not found error.

If you add:

echo foo                                                                        
ehco foo2

if [ 1 -lt 0 ]                                                                  
then                                                                            
    echo 123                                                                    
done                                                                            

Then run:

$ ksh -n foo.sh 
foo.sh: syntax error at line 9: `done' unexpected
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.