Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 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 | |
Chet Ramey | ac50fba | 2014-02-26 09:36:43 -0500 | [diff] [blame] | 14 | # 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 Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 31 | [ $# -lt 1 ] && { |
| 32 | echo "zprintf: usage: zprintf format [args ...]" >&2 |
| 33 | exit 2 |
| 34 | } |
| 35 | |
| 36 | fmt="${1%,}" |
| 37 | shift |
| 38 | |
| 39 | for a in "$@"; do |
| 40 | args="$args,\"${a%,}\"" |
| 41 | done |
| 42 | |
| 43 | gawk "BEGIN { printf \"$fmt\" $args }" |