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