Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!snorkelwacker.mit.edu!stanford.edu!unix!ctnews!pyramid!octopus!satyr!ditka!teda!netcomsv!amdcad!sono!porky!mayer From: mayer@sono.uucp (Ronald &) Newsgroups: comp.lang.perl Subject: re: chsh /usr/bin/perl [writing a shell in perl] Message-ID: Date: 27 Jun 91 16:21:14 GMT Sender: mayer@sono.uucp (Ronald Mayer) Organization: Acuson Lines: 74 In a recent article tchrist@convex.COM (Tom Christiansen) writes: > >It would be too hard to type commands in, which after all is what shells >are all about. Everything would be system thing, or print `foo` that. > I don't think that was the question. I'm rather sure the original poster intended to run a perl script as his login shell. [Anyway, perl with now arguments or script is a pretty boring shell because the only way I can get it to eval anything is with an EOF.] If he believes everything the FAQ says about interactive perl scripts, he might be tempted to use something like "perl -de 0" as a login shell, but this is rather clumsy. It's quite trivial to make a reasonable shell in perl. All you need to do is have a script which does this: loop forever { Get a line of input from the user. If desired, process the input by 'eval(@aliases)' or similar. Try to eval the input. If the command eval's successfully, 'next' If the command successfully executes as a unix program, 'next' If $@ tells you eval failed because of "syntax error .* at EOF", continue appending lines of input to the command until it evals successfully or it gives you a real syntax error. [This lets you enter multi-line perl commands like for loops.] } continue { print the output of the eval or unix_command } The GOOD thing about using perl scripts as a shell is that you can program it to use whatever aliasing, history, builtin-command, flow-control, etc, etc, mechanism you want to apply to the user's input. Ron