home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume5
/
unshar.perl
< prev
next >
Wrap
Internet Message Format
|
1989-02-03
|
2KB
Path: xanth!nic.MR.NET!hal!ncoast!allbery
From: grady@fxgrp.UUCP (Steven Grady)
Newsgroups: comp.sources.misc
Subject: v05i050: perl version of unshar
Message-ID: <865@fxgrp.UUCP>
Date: 15 Nov 88 00:32:17 GMT
Sender: allbery@ncoast.UUCP
Reply-To: grady@fxgrp.UUCP (Steven Grady)
Organization: FX Development Group, Inc., Mountain View, CA
Lines: 47
Approved: allbery@ncoast.UUCP
Posting-number: Volume 5, Issue 50
Submitted-by: "Steven Grady" <grady@fxgrp.UUCP>
Archive-name: unshar.perl
Quick and dirty, but it works. Additional features/bug-fixes welcome.
#! /usr/bin/perl
# usage: unshar [-v] file ...
# Assumes the files are well-defined.
# For reasons unclear to me, the eof check prevents the
# last line in the file from being executed. This is not
# a problem for most shar files.
do 'getopt.pl';
do Getopt();
if ($opt_v) {
open(out, ">&stdout") || die "Can't open >&stdout";
} else {
open(out, ">/dev/null") || die "Can't open >/dev/null";
}
# Lots of clever changes cold be made -- find the '#!' line and
# execute the program; figure out what kind of file it is
# if it turns out not to be a shar; etc.. Currently it is functional.
open(sh, "|/bin/sh") || die "Can't open |/bin/sh";
select(out);
while (<>) {
# Give up on the shell when we see "exit 0" or at the end of the file
if (eof || /^exit 0/) {
select(out) || die "Can't select out";
close(sh) || die "Can't close sh";
open(sh, "|/bin/sh") || die "Can't open |/bin/sh";
# start a new shell after seeing either "/bin/sh" or "cut here"
} elsif (m#/bin/sh# || /cut here/i) {
select(sh) || die "Can't select sh";
# otherwise, spew the output to current selection (shell, stdout, /dev/null)
} else {
print;
}
}