1*8462SApril.Chin@Sun.COM#!/usr/bin/ksh93 2*8462SApril.Chin@Sun.COM 3*8462SApril.Chin@Sun.COM# 4*8462SApril.Chin@Sun.COM# CDDL HEADER START 5*8462SApril.Chin@Sun.COM# 6*8462SApril.Chin@Sun.COM# The contents of this file are subject to the terms of the 7*8462SApril.Chin@Sun.COM# Common Development and Distribution License (the "License"). 8*8462SApril.Chin@Sun.COM# You may not use this file except in compliance with the License. 9*8462SApril.Chin@Sun.COM# 10*8462SApril.Chin@Sun.COM# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 11*8462SApril.Chin@Sun.COM# or http://www.opensolaris.org/os/licensing. 12*8462SApril.Chin@Sun.COM# See the License for the specific language governing permissions 13*8462SApril.Chin@Sun.COM# and limitations under the License. 14*8462SApril.Chin@Sun.COM# 15*8462SApril.Chin@Sun.COM# When distributing Covered Code, include this CDDL HEADER in each 16*8462SApril.Chin@Sun.COM# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 17*8462SApril.Chin@Sun.COM# If applicable, add the following below this CDDL HEADER, with the 18*8462SApril.Chin@Sun.COM# fields enclosed by brackets "[]" replaced with your own identifying 19*8462SApril.Chin@Sun.COM# information: Portions Copyright [yyyy] [name of copyright owner] 20*8462SApril.Chin@Sun.COM# 21*8462SApril.Chin@Sun.COM# CDDL HEADER END 22*8462SApril.Chin@Sun.COM# 23*8462SApril.Chin@Sun.COM 24*8462SApril.Chin@Sun.COM# 25*8462SApril.Chin@Sun.COM# Copyright 2008 Sun Microsystems, Inc. All rights reserved. 26*8462SApril.Chin@Sun.COM# Use is subject to license terms. 27*8462SApril.Chin@Sun.COM# 28*8462SApril.Chin@Sun.COM 29*8462SApril.Chin@Sun.COM# 30*8462SApril.Chin@Sun.COM# shlint - a simple lint wrapper around "shcomp" 31*8462SApril.Chin@Sun.COM# 32*8462SApril.Chin@Sun.COM 33*8462SApril.Chin@Sun.COM# Solaris needs /usr/xpg6/bin:/usr/xpg4/bin because the tools in /usr/bin are not POSIX-conformant 34*8462SApril.Chin@Sun.COMexport PATH=/usr/xpg6/bin:/usr/xpg4/bin:/bin:/usr/bin 35*8462SApril.Chin@Sun.COM 36*8462SApril.Chin@Sun.COM# Make sure all math stuff runs in the "C" locale to avoid problems 37*8462SApril.Chin@Sun.COM# with alternative # radix point representations (e.g. ',' instead of 38*8462SApril.Chin@Sun.COM# '.' in de_DE.*-locales). This needs to be set _before_ any 39*8462SApril.Chin@Sun.COM# floating-point constants are defined in this script). 40*8462SApril.Chin@Sun.COMif [[ "${LC_ALL}" != "" ]] ; then 41*8462SApril.Chin@Sun.COM export \ 42*8462SApril.Chin@Sun.COM LC_MONETARY="${LC_ALL}" \ 43*8462SApril.Chin@Sun.COM LC_MESSAGES="${LC_ALL}" \ 44*8462SApril.Chin@Sun.COM LC_COLLATE="${LC_ALL}" \ 45*8462SApril.Chin@Sun.COM LC_CTYPE="${LC_ALL}" 46*8462SApril.Chin@Sun.COM unset LC_ALL 47*8462SApril.Chin@Sun.COMfi 48*8462SApril.Chin@Sun.COMexport LC_NUMERIC=C 49*8462SApril.Chin@Sun.COM 50*8462SApril.Chin@Sun.COMfunction fatal_error 51*8462SApril.Chin@Sun.COM{ 52*8462SApril.Chin@Sun.COM print -u2 "${progname}: $*" 53*8462SApril.Chin@Sun.COM exit 1 54*8462SApril.Chin@Sun.COM} 55*8462SApril.Chin@Sun.COM 56*8462SApril.Chin@Sun.COMfunction usage 57*8462SApril.Chin@Sun.COM{ 58*8462SApril.Chin@Sun.COM OPTIND=0 59*8462SApril.Chin@Sun.COM getopts -a "${progname}" "${shlint_usage}" OPT '-?' 60*8462SApril.Chin@Sun.COM exit 2 61*8462SApril.Chin@Sun.COM} 62*8462SApril.Chin@Sun.COM 63*8462SApril.Chin@Sun.COM# program start 64*8462SApril.Chin@Sun.COMbuiltin basename 65*8462SApril.Chin@Sun.COM 66*8462SApril.Chin@Sun.COMtypeset progname="${ basename "${0}" ; }" 67*8462SApril.Chin@Sun.COM 68*8462SApril.Chin@Sun.COMtypeset -r shlint_usage=$'+ 69*8462SApril.Chin@Sun.COM[-?\n@(#)\$Id: shlint (Roland Mainz) 2008-10-14 \$\n] 70*8462SApril.Chin@Sun.COM[-author?Roland Mainz <roland.mainz@sun.com>] 71*8462SApril.Chin@Sun.COM[-author?Roland Mainz <roland.mainz@nrubsig.org>] 72*8462SApril.Chin@Sun.COM[+NAME?shlint - lint for POSIX shell scripts] 73*8462SApril.Chin@Sun.COM[+DESCRIPTION?\bshlint\b is a lint for POSIX shell scripts.] 74*8462SApril.Chin@Sun.COM[+SEE ALSO?\bshcomp\b(1), \bksh93\b(1)] 75*8462SApril.Chin@Sun.COM' 76*8462SApril.Chin@Sun.COM 77*8462SApril.Chin@Sun.COMwhile getopts -a "${progname}" "${shlint_usage}" OPT ; do 78*8462SApril.Chin@Sun.COM# printmsg "## OPT=|${OPT}|, OPTARG=|${OPTARG}|" 79*8462SApril.Chin@Sun.COM case ${OPT} in 80*8462SApril.Chin@Sun.COM *) usage ;; 81*8462SApril.Chin@Sun.COM esac 82*8462SApril.Chin@Sun.COMdone 83*8462SApril.Chin@Sun.COMshift $((OPTIND-1)) 84*8462SApril.Chin@Sun.COM 85*8462SApril.Chin@Sun.COMfile="$1" 86*8462SApril.Chin@Sun.COM[[ ! -f "$file" ]] && fatal_error $"File ${file} not found." 87*8462SApril.Chin@Sun.COM[[ ! -r "$file" ]] && fatal_error $"File ${file} not readable." 88*8462SApril.Chin@Sun.COM 89*8462SApril.Chin@Sun.COMx="$( /usr/bin/ksh93 -n "${file}" 2>&1 1>/dev/null )" 90*8462SApril.Chin@Sun.COM 91*8462SApril.Chin@Sun.COMprintf "%s" "$x" 92*8462SApril.Chin@Sun.COM 93*8462SApril.Chin@Sun.COM[[ "$x" != "" ]] && exit 1 || exit 0 94*8462SApril.Chin@Sun.COM# EOF. 95