$ 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?
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
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)