![]() |
![]()
| ![]() |
![]()
NAMEpsh - Perl SHell SYNOPSISThe Perl Shell documentation has been split into a number of different manpages: psh This overview pshdevel Developing for the Perl Shell pshconfig Configuring the Perl Shell pshcomplete TAB completions in the Perl Shell DESCRIPTIONpsh is a Perl program which executes a read-eval loop with enough options so that general behavior reasonably similar to more traditional shells like 'sh' or 'bash' can be achieved, while still allowing arbitrary perl expressions to be evaluated. By default within psh, the Perl -w flag and '"use strict"' are not employed so that the user is not bound by their stipulations. They can both be turned on via a command-line flag; or setting "$^W = 1" will turn on warnings, and calling '"use strict"' will (almost) do the usual thing if called by the user (see LIMITATIONS, below). Each line of input is read. psh knows a number of possible strategies for evaluating the line, such as "send it to system() if it starts with the name of an executable visible in $ENV{PATH}". (See below for a complete list.) Each strategy in turn (from a user-definable list) examines the command line to see if it can apply, and the first matching strategy evaluates the line. There is a psh configuration variable (see below) which controls whether the perl value of the evaluation is saved and printed after each command. psh automatically collects several lines of input into a unit processed as a single line if there are unfinished Perl constructs on the line. In particular, if there is an unmatched quote, paren, brace, or square bracket, input is read until these characters match. If an input line contains the Perl "here document" construct as in "<<XXX", (anywhere on the line), then input is read and accumulated until "XXX" occurs on a line by itself. Then the accumulated input is processed as if it were a single line. OPTIONSThe command-line arguments to psh are: psh [-d [options]] [-w] [-F] [-f RC_FILE] [-c STRING ] [FILE1 FILE2 ....] They are processed in the following order, regardless of what order they are specified in:
If any FILE1 ... arguments are specified on the command line, they will be read and executed and then psh will exit. Otherwise, psh will enter an interactive command loop. TOKENIZATIONSome evaluation strategies examine the "words" of the input. These are produced by a tokenizer which behaves very similarly to traditional shells: words are broken at whitespace, '&' is a metacharacter which means that it always forms its own word, and backslash and double and single quotes act as quoting characters, preventing word breaks at whitespace and the "meta-ness" of &. If the description of the strategy does not mention the "words", then the tokenization is irrelevant to that strategy. STANDARD EVALUATION STRATEGIESpsh includes the following evaluation strategies, sorted by the default order. For adding/removing evaluation strategies we suggest the usage of the built-in command "strategy" from within psh.
GLOBBINGGlobbing is used to expand filenames against patterns. Perl Shell understands the sh '*' and '?' globbing characters (where * matches any string and ? matches exactly one character). In addition, Perl Shell knows the very powerful '**' globbing, replacing many "find"s in your daily work. '**' will be replaced by 'current directories and all sub directories'. For example: grep foo lib/**/*.pm will search for foo in all *.pm files which are somewhere (recursivly) within the lib directory. REDIRECTSThe standard output may be redirected to a file with command > file and the standard input may be taken from a file with command < file File descriptors other than 0 and 1 may be specified in an rc-like syntax. To redirect standard error to a file use: command >[2] file (this is 'command 2> file' in sh-derivatives! sh-syntax is not supported) To redirect both, standard output and standard error use: command >[all] file It's also possible to redirect to opened Perl filehandles. If you e.g. opened a handle "FOO" for writing you may use: command >[=FOO] to write to that filehandle. PIPELINESPipelines are used to construct processing chains. cat a.txt b.txt | wc -l This is the same as in other shells - standard output of the first command will be standard input of the second command. To redirect different file descriptors, use e.g. command |[5] command2 to redirect file descriptor 5 to standard input of command. It is also possible to redirect to a different filedescriptor than standard input for the right-hand command: command |[1=5] command2 will redirect standard output from the first command to a newly opened stream on file descriptor 5 for command. Thus, 'command | command' is only a short hand version of 'command |[1=0] command'. An alias is provided for piping standard error and standard output at the same time: command |[all] command2 will pipe both to command2 and is so an easier to remember version of command >[2=1] | command2 MANIFEST FILTERSA manifest filter is a chunk of code that causes the creation of a filter process. They are handy for creating simple one-time filters because they don't require creating a program file, setting permissions and so on. There are three kinds of manifest filters: quick, grep and substitution. A quick filter consists of a block of code surrounded by curly braces, with a trailing '"q"' modifier. The Perl Shell turns this into a line-by-line filter. For the code in the braces, $_ will contain the line as it was read from input (including any end-of-line character). The filter block should ls | { print ++$i, ": $_"; }q A grep filter consists of a block of code surrounded by curly braces, with a trailing '"g"' modifier. The Perl Shell turns this into a line-by-line filter. Only those lines for which the code in the braces returns a true value will be printed. For the code in the braces, @_ will contain the results of splitting $_ with the pattern "\s+". netstat | { $_[1]>2; }g A substitution filter consists of a perl-style s/// operator instance. The Perl Shell will turn this into a line-by-line filter that performs the substitution on each line, and then prints the line. For example: ls | s/a/b/ A substitution filter is logically equivalent to a block filter containing the substitution and a statement to print the resulting line. The example above is equivalent to: ls | { s/a/b/; print; }q BUILT-IN FUNCTIONSA list of built in functions is available from within "psh" using the "help" command. For details about the implementation of built-ins, please see the pshdevel manpage. PSH FUNCTIONS
There are other functions in the Psh:: package, but they are probably not useful except internally to psh. LIMITATIONSDue to limitations of the Win32 type of operating system there's no job control available on those systems. The loop inside psh will clobber $1 and other Perl-builtin variables because it uses matches to implement some of its special functions. Right now, job control simply assumes that the POSIX interface is fully implemented. There should be a way to turn job control off if this is not the case. The "exit status" of programs invoked in the foreground by the "executable" strategy (or even the "bang" strategy) isn't available from within psh. Note that since expressions like 'use foo' return undef when sent to eval(), it is not possible to use that return value as indication of an error. Instead, we use the heuristic that there was no error unless the special Perl variable '$@' is non-empty. Note that the side effects of 'use foo' as a psh command line appear to be exactly as expected. REQUIREMENTSpsh needs several optional Perl modules to offer full functionality:
OTHER PERL SHELLSLarry Walls' Perl ShellLarry Wall exhibits the simple Perl shell "while (<>) { eval; print $@; }" on page 161 of the Camel Book (2nd Edition). lpshLee Eakin <leakin@dfw.nostrum.com> has written the Fancy Poor Man's Perl SHell (called lpsh for Lee's Perl Shell), a simple Perl shell that he has used for a number of years now (it is derived from Larry Wall's Perl Shell). He has added some numeric conversion functions because he often uses it as a calculator. He has placed it on the web at "http://www.dfw.nostrum.com/~leakin/psh" (for the code) and "http://www.dfw.nostrum.com/~leakin/psh.README" for a short explanation of the code and a reference to the main Perl Shell site. Perl Debugger ShellRich Graves <rcgraves@brandeis.edu> posted a comment to the original psh-0.001 announcement on "http://freshmeat.net", which contained this gem that leverages the Perl debugger: "perl -d -e 1"; perlshHiroo Hayashi <hiroo.hayashi@computer.org> includes perlsh, a ``one-line perl evaluator with line editing function and variable name completion function'' as an example with his Term::ReadLine::Gnu Perl module. PSH.pmIn an example of convergent evolution, at "http://jenda.krynicky.cz/" there is a Perl shell module called PSH.pm which is quite similar to this psh. It is designed to provide a command line that can be called inside some other program via "PSH::prompt();", but a small file psh.pl is also included that uses PSH to provide a standalone shell. Perhaps some merger of these efforts would be beneficial to all? SoftListSome versions of the Perl faq mention an interactive Perl shell called SoftList, which can still be found at "http://www.mit.edu/afs/sipb/contrib/perl/SoftList/". It predates Term::Readline and was apparently last touched in 1993, so it seems to be obsolescent. timtoshTim Newsome, <nuisance@cmu.edu>, has developed a shell he calls timtosh (There Is More Than One SHell). Per his web site ("http://www.wiw.org/~drz/timtosh"), it is a shell written entirely in Perl. The goal is to get a shell which you can extend in Perl and can do some other niceties related to Perl (like perl re file matching). As of 1999-12-13 (Perl Shell 0.004 release date), Tim says timtosh ``is focused quite differently than psh is, but is currently still waiting for a rewrite of the command line parsing. (It has been for almost a year now)''. vbshTom Christiansen and Nathan Torkington's book Perl Cookbook, published by O'Reilly in 1998 (ISBN 1-56592-243-3) has "Example 15-4. vbsh" on page 531 for section 15.11 (Editing Input). It stands for Very Bad SHell. Comparison of perl shellsAs an aid to comparing/contrasting these different shells, here is a brief table indicating whether or not each has certain features. Key to features: PE : Perl evaluation of Perl expressions SHE: shell-like evaluation of shell-like expressions, including 'exec'ing executables searched for in PATH CLE: command-line editing JC : job control PL : pipelines Key to symbols: * : feature present - : feature absent ? : don't know The shells: Shell Name PE SHE CLE JC PL psh (this one) * * * * * Larry Wall shell * - - - - lpsh * - * - - Perl debugger shell * - * - - perlsh * - * - - Krynicky PSH.pm * * ? - ? SoftList * ? * ? ? timtosh - * * * * vbsh ? ? ? ? - FILESpsh - The Perl Shell executable script. .pshrc - The user's Perl Shell `profile'. May be in $HOME or the current directory; if both are present, both will be read in the order mentioned. COPYRIGHTCopyright (C) 1999-2003 Gregor N. Purdy. All rights reserved. This script is free software. It may be copied or modified according to the same terms as Perl itself. E<lt>F<gregor@focusresearch.com>E<gt> CREDITSThe following people have contributed to the development of "psh":
|