[comp.lang.perl] Perl Shell

scs@iti.org (Steve Simmons) (01/04/90)

Just throwing out an idea -- anybody tried using perl as a shell?
Psh = perl shell, pshaw = perl shell actually works?

lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (01/05/90)

In article <4723@itivax.iti.org> scs@iti.org (Steve Simmons) writes:
: 
: Just throwing out an idea -- anybody tried using perl as a shell?
: Psh = perl shell, pshaw = perl shell actually works?

Look at the file "perlsh" in the perl distribution directory.

To do a proper shell, the parser would have to be changed to do incremental
compilation and execute whenever there was something complete to execute.
You'd want better job control, and more concise ways to invoke programs.

But I still wouldn't want to use it as a shell.

Larry

igp@torch.co.uk (Ian Phillipps) (01/12/90)

lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) writes:

>In article <4723@itivax.iti.org> scs@iti.org (Steve Simmons) writes:
>: Just throwing out an idea -- anybody tried using perl as a shell?

>Look at the file "perlsh" in the perl distribution directory.

Also, Larry doesn't say that you can use the -d option as a perl shell!

I find the following quite useful for testing perl out.  It's found three
bugs in perl so far. :-) I hope you like the default prompt.
Could be written better using packages, but I haven't needed to convert it yet.
Main problem is that $_ gets smashed by each iteration of the interpreter.

Note that by default the result of the last (scalar) expression gets
printed; apparently spurious "1"s are the result of successful printing, etc.

------ cut here and hack to taste ----
#!/usr/local/bin/perl
eval "exec perl -S $0 $*"
	if $running_under_some_shell;

$Prompt = ' $_: ';
$Printing = "\n";
print $Prompt;
while(<stdin>) {
	$Pres = eval $_ . ';';
	print $Pres.$Printing if $Printing;
	print $@;
	print $Prompt;
	}