File: save

package info (click to toggle)
lmbench 3.0-a9%2Bdebian.1-3
  • links: PTS
  • area: non-free
  • in suites: bullseye
  • size: 2,752 kB
  • sloc: ansic: 12,328; perl: 6,531; sh: 3,965; makefile: 730
file content (27 lines) | stat: -rwxr-xr-x 644 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/env perl
# Save the input in the specified file if possible.  If the file exists,
# add a numeric suffice, i.e., .1, and increment that until the file
# does not exist.  Use the first name found as the file to save.
#
# Typical usage is: xroff -man -fH *.1 | save MAN.PS
#
# Hacked into existence by Larry McVoy (lm@sun.com now lm@sgi.com).
# Copyright (c) 1994 Larry McVoy.  GPLed software.
# $Id$
eval 'exec perl -Ssw $0 "$@"'
	if 0;

$base = $#ARGV == 0 ? shift : "save";
$file = $base;
$ext = 1;

while (-e $file) {
	$file = "$base.$ext";
	$ext++;
}
warn "Saving in $file\n";
open(FD, ">$file");
while(<>) {
	print FD;
}
exit 0;