Checking ksh script syntax


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Checking ksh script syntax
# 1  
Old 12-15-2009
Checking ksh script syntax

To check a bash script syntax without executing it we use:
Code:
bash -n scriptname

What should be the equivalent command for checking a ksh script?
# 2  
Old 12-15-2009
Code:
ksh -n scriptname

# 3  
Old 12-15-2009
I have a script:

[CODE][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
Code:
 ksh load_avg_alert.sh

I get no error as output.

But when i run
Code:
ksh -n load_avg_alert.sh

i get the following error:
Code:
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?

Last edited by proactiveaditya; 12-21-2009 at 07:16 AM..
# 4  
Old 12-15-2009
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: -

Code:
$(...)

would be better.
# 5  
Old 12-15-2009
Ok got it
# 6  
Old 12-15-2009
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 !
# 7  
Old 12-15-2009
Command substitution can also be nested using backtick.

Last edited by proactiveaditya; 12-21-2009 at 01:47 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ksh Script - Syntax error `done' unexpected

Hello, I am working on my first ksh script to review daily reports. The script uses different functions to check different types of reports in csv format. A control file gets read in with information regarding the report, other info, and the function to use. When I run the script I get the... (4 Replies)
Discussion started by: bot9196
4 Replies

2. Shell Programming and Scripting

Checking numeric expression in .ksh script

Gurus, Please need your help. I'm saving a filetimestamp into $filetimestamp and say....echo $filetimestamp gives 2015021612 I'm saving a cutoff_time into $cutoff_time say....echo $cutoff_time gives 2015021514 now my requirement is to check if $filetimestamp is greater than... (4 Replies)
Discussion started by: thummi9090
4 Replies

3. Shell Programming and Scripting

Checking LB status.. stuck in script syntax of code

#!/bin/ksh #This script will check status of load balancer in AIX servers from hopbox #Steps to do as folows : #Login to server #netstat -ani | grep <IP> #check if the output contains either lo0 OR en0 #if the above condition matches, validation looks good #else, send an email with impacted... (7 Replies)
Discussion started by: vinil
7 Replies

4. Shell Programming and Scripting

ksh-script "arithmetic syntax error" comparing strings

Hi all, Iīve already searched the forum but canīt find what i am doing wrong. I am trying to compare two variables using ksh under red hat. The error I get is: -ksh: .: MDA=`md5sum /tmp/ftp_dir_after_transfer | cut -d' ' -f1 ` MDB=`md5sum /tmp/ftp_dir_before_transfer | cut -d' ' -f1 `... (3 Replies)
Discussion started by: old_mike
3 Replies

5. Shell Programming and Scripting

checking variable has value - ksh

hi all, i have a shell (ksh) script where i am reading line by line from a grep command and i wanted to check if the grep command actually returned something or was null. i can do this by using -z : if ; then ..... but this forces me to do something when $myVariable is null when i... (3 Replies)
Discussion started by: cesarNZ
3 Replies

6. UNIX for Dummies Questions & Answers

KSH Checking Previous Date**

How would I go about getting the previous date on the server? I'm out of ideas...I am thinking that I could do it using the date command, but I am unable to find any information on doing it. For example if the current date is April 17th 2008 it would be (20080417) <- (YYYYMMDD). I need the previous... (4 Replies)
Discussion started by: developncode
4 Replies

7. UNIX for Dummies Questions & Answers

ksh Checking if variable has 5 digits

How could I check if a numeric variable has 5 digits in KSH...I have a zipcode variable that I know will always be 5 digits, and I want to print out an error if it is less or more than 5 digits the problem is that I have it as: if ] but this won't work because the statement doesn't see 0001 as... (3 Replies)
Discussion started by: developncode
3 Replies

8. UNIX for Dummies Questions & Answers

Ksh Checking if string has 2 characters and does not contain digits?

How could I check if a string variable contains at least (or only) 2 characters, and check and make sure that the string does not contain any numeric digits?...I need to know how to do this as simple as possible. and I am using the Ksh shell. Thanks. (1 Reply)
Discussion started by: developncode
1 Replies

9. Shell Programming and Scripting

.sh file syntax checking script

This isn't a question--its a solution! Below is a script that I wrote for my own script file development which does what the title says. Its the closest that you can get to compiling what are otherwise purely interpreted script files. I offer it here simply for the benefit of anyone else writing... (12 Replies)
Discussion started by: fabulous2
12 Replies

10. UNIX for Dummies Questions & Answers

Script syntax checking

Is it possible to check the script syntax with some sort of command...? Without running the script . I'm using Sun Solaris (3 Replies)
Discussion started by: bjornrud
3 Replies
Login or Register to Ask a Question