blob: 86f9e95fa9c9ec58e633a67a6c60deb3d1be7cac [file] [log] [blame]
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001#! /bin/bash
2#
3# zprintf - function that calls gawk to do printf for those systems that
4# don't have a printf executable
5#
6# The format and arguments can have trailing commas, just like gawk
7#
8# example:
9# zprintf 'Eat %x %x and suck %x!\n' 57005 48879 64206
10#
11# Chet Ramey
12# chet@po.cwru.edu
13
Chet Rameyac50fba2014-02-26 09:36:43 -050014# Copyright 1996 Chester Ramey
15#
16# This program is free software; you can redistribute it and/or modify
17# it under the terms of the GNU General Public License as published by
18# the Free Software Foundation; either version 2, or (at your option)
19# any later version.
20#
21# TThis program is distributed in the hope that it will be useful,
22# but WITHOUT ANY WARRANTY; without even the implied warranty of
23# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24# GNU General Public License for more details.
25#
26# You should have received a copy of the GNU General Public License
27# along with this program; if not, write to the Free Software Foundation,
28# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29
30
Jari Aaltoccc6cda1996-12-23 17:02:34 +000031[ $# -lt 1 ] && {
32 echo "zprintf: usage: zprintf format [args ...]" >&2
33 exit 2
34}
35
36fmt="${1%,}"
37shift
38
39for a in "$@"; do
40 args="$args,\"${a%,}\""
41done
42
43gawk "BEGIN { printf \"$fmt\" $args }"