Bash-4.3 distribution sources and documentation
[platform/upstream/bash.git] / examples / scripts / center
1 #! /bin/bash
2 #
3 # center - center a group of lines
4 #
5 # tabs in the lines might cause this to look a little bit off
6 #
7 #
8 #  Chet Ramey <chet.ramey@case.edu>
9 #
10 #  Copyright 1999 Chester Ramey
11 #
12 #   This program is free software; you can redistribute it and/or modify
13 #   it under the terms of the GNU General Public License as published by
14 #   the Free Software Foundation; either version 2, or (at your option)
15 #   any later version.
16 #
17 #   TThis program is distributed in the hope that it will be useful,
18 #   but WITHOUT ANY WARRANTY; without even the implied warranty of
19 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 #   GNU General Public License for more details.
21 #
22 #   You should have received a copy of the GNU General Public License
23 #   along with this program; if not, write to the Free Software Foundation,
24 #   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25
26 width=${COLUMNS:-80}
27
28 if [[ $# == 0 ]]
29 then
30         set -- /dev/stdin
31 fi
32
33 for file
34 do
35         while read -r
36         do
37                 printf "%*s\n" $(( (width+${#REPLY})/2 )) "$REPLY"
38         done < $file
39 done
40
41 exit 0