Checking ksh script syntax

To check a bash script syntax without executing it we use:

bash -n scriptname

What should be the equivalent command for checking a ksh script?

ksh -n scriptname

I have a script:

[root@wiki ~]# cat load_avg_alert.sh
#!/bin/ksh


UPTIME=`uptime|grep -o 'load.*'|sed 's/[,|:]//g'`

avg1min=`echo "$UPTIME"|grep -o "load average.*"|awk '{print $3}'`
avg5min=`echo "$UPTIME"|grep -o "load average.*"|awk '{print $4}'`
avg15min=`echo "$UPTIME"|grep -o "load average.*"|awk '{print $5}'`

When i run
 ksh load_avg_alert.sh

I get no error as output.

But when i run

ksh -n load_avg_alert.sh

i get the following error:

load_avg_alert.sh: warning: line 4: `...` obsolete, use $(...)
load_avg_alert.sh: warning: line 6: `...` obsolete, use $(...)
load_avg_alert.sh: warning: line 7: `...` obsolete, use $(...)
load_avg_alert.sh: warning: line 8: `...` obsolete, use $(...)
load_avg_alert.sh: warning: line 10: `...` obsolete, use $(...)
load_avg_alert.sh: warning: line 12: `...` obsolete, use $(...)

Why is that?

These are warnings not errors. They probably refer to obsolete syntax that still works but has been superceded. By the look of it you have code that use backticks when: -

$(...)

would be better.

Ok got it

It's justa that the backticks are a bit obsolete. It's better tu use $(...). 2 good reasons:

  1. The command substitutions can be nested.
  2. The script is more readable.
    But it's not an error !

Command substitution can also be nested using backtick.

example:

VAR=$(echo "Now it is $(date)")
echo "$VAR"

thanks