The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #3 (permalink)  
Old 11-08-2007
drl's Avatar
drl drl is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2007
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 712
Hi.

This might help, at least in the early stages of developing an awk script:

Code:
#!/usr/bin/env sh

# @(#) a1       Demonstrate one debugging feature in [g]awk.

set -o nounset
echo

## Use local command version for the commands in this demonstration.

echo "(Versions displayed with local utility \"version\")"
version >/dev/null 2>&1 && version bash awk

echo

awk --lint '
b == 1  { print " Found case for value of b is 1." }
' data1

exit 0

Producing:

Code:
% ./a1

(Versions displayed with local utility "version")
GNU bash 2.05b.0
GNU Awk 3.1.4

awk: cmd. line:2: (FILENAME=data1 FNR=1) warning: reference to uninitialized variable `b'
awk: cmd. line:2: (FILENAME=data1 FNR=2) warning: reference to uninitialized variable `b'
awk: cmd. line:2: (FILENAME=data1 FNR=3) warning: reference to uninitialized variable `b'

However, most awk scripts are so short that it probably is not worth anyone's time to put in a lot of work doing a full debugger (well, it might be worth a grad student's time perhaps )

See info awk for the situations about which --lint will complain ... cheers, drl