# Checking ksh script syntax

**URL:** <https://community.unix.com/t/checking-ksh-script-syntax/255859>\
**Category:** Shell Programming and Scripting\
**Created:** [December 15, 2009, 9:27am UTC](https://community.unix.com/t/checking-ksh-script-syntax/255859 "2009-12-15T09:27:31Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![proactiveaditya](https://community.unix.com/letter_avatar/proactiveaditya/32/6_449c533f586939b6e5f246632a46421f.png) [@proactiveaditya](https://community.unix.com/u/proactiveaditya)\
**Post date:** [December 15, 2009, 9:27am UTC](https://community.unix.com/t/checking-ksh-script-syntax/255859/1 "2009-12-15T09:27:31Z")

</div>

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

```nohighlight
bash -n scriptname

```

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

---

<div class="post-metadata">

**Author:** ![steadyonabix](https://community.unix.com/letter_avatar/steadyonabix/32/6_449c533f586939b6e5f246632a46421f.png) [@steadyonabix](https://community.unix.com/u/steadyonabix)\
**Post date:** [December 15, 2009, 9:32am UTC](https://community.unix.com/t/checking-ksh-script-syntax/255859/2 "2009-12-15T09:32:49Z")

</div>

```nohighlight
ksh -n scriptname

```

---

<div class="post-metadata">

**Author:** ![proactiveaditya](https://community.unix.com/letter_avatar/proactiveaditya/32/6_449c533f586939b6e5f246632a46421f.png) [@proactiveaditya](https://community.unix.com/u/proactiveaditya)\
**Post date:** [December 15, 2009, 9:39am UTC](https://community.unix.com/t/checking-ksh-script-syntax/255859/3 "2009-12-15T09:39:03Z")

</div>

I have a script:

```nohighlight
[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

```nohighlight
ksh -n load_avg_alert.sh

```

i get the following error:

```nohighlight
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?

---

<div class="post-metadata">

**Author:** ![steadyonabix](https://community.unix.com/letter_avatar/steadyonabix/32/6_449c533f586939b6e5f246632a46421f.png) [@steadyonabix](https://community.unix.com/u/steadyonabix)\
**Post date:** [December 15, 2009, 9:53am UTC](https://community.unix.com/t/checking-ksh-script-syntax/255859/4 "2009-12-15T09:53:27Z")

</div>

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: -

```nohighlight
$(...)

```

would be better.

---

<div class="post-metadata">

**Author:** ![proactiveaditya](https://community.unix.com/letter_avatar/proactiveaditya/32/6_449c533f586939b6e5f246632a46421f.png) [@proactiveaditya](https://community.unix.com/u/proactiveaditya)\
**Post date:** [December 15, 2009, 9:56am UTC](https://community.unix.com/t/checking-ksh-script-syntax/255859/5 "2009-12-15T09:56:44Z")

</div>

Ok got it

---

<div class="post-metadata">

**Author:** ![frans](https://community.unix.com/user_avatar/community.unix.com/frans/32/1697_2.png) [@frans](https://community.unix.com/u/frans)\
**Post date:** [December 15, 2009, 9:56am UTC](https://community.unix.com/t/checking-ksh-script-syntax/255859/6 "2009-12-15T09:56:45Z")

</div>

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 !

---

<div class="post-metadata">

**Author:** ![proactiveaditya](https://community.unix.com/letter_avatar/proactiveaditya/32/6_449c533f586939b6e5f246632a46421f.png) [@proactiveaditya](https://community.unix.com/u/proactiveaditya)\
**Post date:** [December 15, 2009, 10:00am UTC](https://community.unix.com/t/checking-ksh-script-syntax/255859/7 "2009-12-15T10:00:05Z")

</div>

Command substitution can also be nested using backtick.

---

<div class="post-metadata">

**Author:** ![frans](https://community.unix.com/user_avatar/community.unix.com/frans/32/1697_2.png) [@frans](https://community.unix.com/u/frans)\
**Post date:** [December 15, 2009, 10:10am UTC](https://community.unix.com/t/checking-ksh-script-syntax/255859/8 "2009-12-15T10:10:51Z")

</div>

example:

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

```

---

<div class="post-metadata">

**Author:** ![proactiveaditya](https://community.unix.com/letter_avatar/proactiveaditya/32/6_449c533f586939b6e5f246632a46421f.png) [@proactiveaditya](https://community.unix.com/u/proactiveaditya)\
**Post date:** [December 15, 2009, 10:15am UTC](https://community.unix.com/t/checking-ksh-script-syntax/255859/9 "2009-12-15T10:15:52Z")

</div>

thanks
