Petit image    Tools


published @ searchlores.org in January 2001
You may enjoy visiting ksoze's page (@ http://www.deny.de/kz/perl.html)
Here is the [perl script], below the help file

ksoze perl shell v0.0 by Ksoze

ksoze perl shell v0.0 help file
-------------------------------
kps is a simple interactive perl shell based on original Larry Wall's "perl -e eval <STDIN> until $@" with some extra feature. It's not definitely meant to be a replacement for your standard shell but it could be quite useful if you want to play with perl "live".

about security
--------------
kps is not meant to be secure. infact you can do any system call by ! command, "rm -rf /" and "format c:\" included.
unix/linux users : DONT RUN THIS SCRIPT SETUID OR SETGID ROOT

install
-------
first , perl 5.004 should be ok.
windows:
unzip kps.pl to any directory.
create a file named kps.bat (in a directory included in your PATH environment var like main system dir, or you'll have to add the dir to your PATH e.g. by editing autoexec.bat) with this line inside :
@perl c:\whatever\you\put\the\script\kps.pl
or @perl kps.pl (if you put the script in perl interpreter's dir)
now you can run the shell by typing at shell prompt (w9x/ME users read 'dos window') : kps

unix/linux:
unzip kps.pl to any directory.
modify the first line of the script (shebang) according to location where perl is on your system.
now you can run the shell by typing path/to/kps.pl or kps.pl (if you put the script in a dir in your path)

the shell
---------
once you run the shell, you get a greeting and a prompt.
now you can type either perl code or one of kps builtin commands.
if kps doesnt recognize a builtin command, it will execute the line of perl code and will prompt again for input.
since kps uses perl "eval" to execute perl code, assignments, sub definitions, etc.. in a line of code will be "remembered" beyond the line execution (untill you quit the shell).

builtin commands (sorted by priority)
----------------
q --> quit the shell
h --> display a brief help
s --> enter shell setup
here you can change a couple of shell settings:
prompt --> the string used as kps prompt
extra_cr --> append a "carriage return" after a line of perl code is executed.
show_predef_symbols --> when listing perl symbols, kps will skip predefined symbols as @ARGV, %INC, STDOUT
warnings --> enable/disable perl warnings
setup accepts 2 command formats :
q --> quit setup
num<space>new_value --> assign "new_value" to setting at index "num"
e.g. you'll get a list like this :
0)extra_cr = 0;
1)prompt = 'Perl >'
2)show_predef_symbols = 1
3)warnings = 1
if you want to change prompt to HelloBaby>>>
command is 1 HelloBaby>>> (that is set id 1 = prompt to HelloBaby>>>)
if you want to skip predefined symbols
command is 2 0 (always 0 = disabled, 1 = enabled)
i think you can easily figure it out
you can change settings at kps execution time, by passing them as parameters,
windows users can change kps.bat file
e.g. @perl c:\whatever\you\put\the\script\kps.pl -p "MyPrompt> " -w 0 -s 0 -e 1
param name is first letter of the verbose name (e.g. prompt = -p)
unix/linux users can create a .sh script to run kps.pl with params
m --> enable disable multi-line code
i am going to give a self explaining example.
you want to define a long subroutine :
sub MySub {
... long code here...
}
since kps evaluates one line of perl code at any time, you cant simply type in code the above way (you'd get perl complaining about "sub MySub {" not being a legal statement) also you dont want to fit that sub in one line, cos it's a lot of code.
no problem, you can type
m
sub MySub {
... long code here...
}
m
all is ok. first m turns on multi-line mode, you can type whatever you want splitted on multiple lines, cos code evaluation is suspended, when kps gets the second m, it evalutes the whole block of code.
Notice : you cant use other builtin commands untill you turn off multi-line mode.
!commands --> commands are directly executed by the system shell
win e.g. !dir (to get list of files in current dir)
linux e.g. !ls (same as above)
perl vars interpolation is allowed
e.g.
$files = '*.gz';
|ls -l $files
so backslash special chars when needed.
?($|@|#|&|f)varname -> report value(s) of "varname" symbol by given context;
again self-explaining examples :
$hello = 'baby';
$hell = 'heaven';
$hellodolly;
@mycats = (tom,tim,tam);
@mycat = ('/etc/password');
%numbers = qw(one 1 two 2 three 3);
open(MYFH,">tempfile.txt");
sub do_nothing { }
# now, you want to look up some value
?$hell
#kps prints $hello = baby $hell = heaven $hellodolly = undef
?$hello
#kps prints $hello = baby
?$
#kps prints every scalar var (and its value) that perl stores internallyv ?@mycat
#kps prints @mycat = (tom,tim,tam);
?@
#kps prints the same as for ?@mycat plus other existing arrays (e.g. @ARGV if show_common_symbols = 1)
?%num
#kps prints %num = (
# one -> 1
# two -> 2
# three -> 3
#)
?fMYFH
# kps prints MYFH is filehandle. f is for filehandles (perl has no such a thing, it's a kps convention)
?&do
# kps prints do_nothing is sub. & is for subs.
?v # kps prints everything in the perl symbols table (package main::)

Notice :
? command skips packages symbols, special variables, kps own vars
and perl predefined symbols (if required)
? param is just a simple regex, dont use special chars cos they'll be backslahed
? command accepts only one param (?$a $b --> BAD)

if none of above matches, line is evaluated as perl code

limitations
-----------
-you should not use symbols beginning with kps_ (e.g. $kps_hello, %kps_hash)
cos you could eventually override script internal vars and fool kps
-variable must be declared as global, (e.g. my $a = 3; kps wont store/track $a)

nice stuff
----------
win users : you can use up and down arrow keys to browse commands history (just like linux users)

ksoze signin off
----------------
this script is free and cant be sold.
you can freely modify code and redistribute it, just consider you could give credits
thanx to Larry Wall for his work and psh by mr. Purdy (a much more complete perl shell)
enjoy perl, learn and give back.


Petit image

(c) 1952-2032: [fravia+], all rights reserved