[tpwd] Fix segfault when exactly one argument given
[tinyapps.git] / add
blob9c1ce5827bc721f8e67bc5abe363051eda0dc871
1 #!/usr/bin/perl -l
2 ##
3 ## Adds text to each line from stdin.
4 ## Copyright (c) 2005 by Stanislaw Klekot (dozzie/AT/irc.pl)
5 ##
6 ## This program is free software; you can redistribute it and/or modify
7 ## it under the terms of the GNU General Public License as published by
8 ## the Free Software Foundation; either version 3 of the License, or
9 ## (at your option) any later version.
11 ## This program is distributed in the hope that it will be useful,
12 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ## GNU General Public License for more details.
16 ## You should have received a copy of the GNU General Public License
17 ## along with this program; if not, see <http://www.gnu.org/licenses/>.
19 ## This is part of Tiny Applications Collection
20 ## -> http://tinyapps.sourceforge.net/
23 # Script adds text from command line to end (or beginning, if specified) of
24 # each line from standard input.
26 # $ printf "123\n321\n***\n" | add aaaaaa
27 # results in
28 # > 123aaaaaa
29 # > 321aaaaaa
30 # > ***aaaaaa
32 if (!@ARGV || $ARGV[0] eq "--help" || $ARGV[0] eq "-h") {
33 $0 =~ s{.*/}{};
34 print "Usage: $0 [-b | --begin | -s | --start] [--] text to add";
35 exit;
38 %arg = qw/-b 1 --begin 1 -s 1 --start 1/;
40 if (exists $arg{$ARGV[0]}) {
41 shift;
42 shift if $ARGV[0] eq "--";
43 $all = "@ARGV";
45 while (<STDIN>) {
46 chomp;
47 print $all, $_;
49 exit;
52 shift if $ARGV[0] eq "--";
53 $all = "@ARGV";
55 while (<STDIN>) {
56 chomp;
57 print $_, $all;