Patch-ID: bash40-021
[bash.git] / examples / scripts / zprintf
blob5e2e3ad81c8d72f792ff0350b5b53398fdf94803
1 #! /bin/bash
3 # zprintf - function that calls gawk to do printf for those systems that
4 # don't have a printf executable
6 # The format and arguments can have trailing commas, just like gawk
8 # example:
9 # zprintf 'Eat %x %x and suck %x!\n' 57005 48879 64206
11 # Chet Ramey
12 # chet@po.cwru.edu
14 [ $# -lt 1 ] && {
15 echo "zprintf: usage: zprintf format [args ...]" >&2
16 exit 2
19 fmt="${1%,}"
20 shift
22 for a in "$@"; do
23 args="$args,\"${a%,}\""
24 done
26 gawk "BEGIN { printf \"$fmt\" $args }"