Line | |
---|
1 | #! /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 |
|
---|
14 | [ $# -lt 1 ] && {
|
---|
15 | echo "zprintf: usage: zprintf format [args ...]" >&2
|
---|
16 | exit 2
|
---|
17 | }
|
---|
18 |
|
---|
19 | fmt="${1%,}"
|
---|
20 | shift
|
---|
21 |
|
---|
22 | for a in "$@"; do
|
---|
23 | args="$args,\"${a%,}\""
|
---|
24 | done
|
---|
25 |
|
---|
26 | gawk "BEGIN { printf \"$fmt\" $args }"
|
---|
Note:
See
TracBrowser
for help on using the repository browser.