File: demo_shell

package info (click to toggle)
libgetopt-declare-perl 1.14-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 328 kB
  • sloc: perl: 1,386; makefile: 8
file content (37 lines) | stat: -rwxr-xr-x 808 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env perl

use strict;
use warnings;
use Getopt::Declare;

my $shell_cmds = <<'EOCMDS';
Commands: [repeatable]

	echo [-n] <words:/.*/>	ECHO WITHOUT NEWLINE 
			{ print $words; print "\n" unless $_PUNCT_{'-n'}; }

	[pvtype: chwho /u?g?a?/]
	[pvtype: chwhat /r?w?x?/]

	chmod [-R] <who:chwho>=<what:chwhat> <files>...	
				CHANGE FILE PERMISSIONS 
			{ foreach (@files) { print "chmod $who=$what $_\n"; } }

	help			SHOW THIS SUMMARY 
			{ $self->usage() }

	exit			EXIT SHELL 
			{ exit }

	<error:/.*/>	 
			{ print "Unknown command: $error\n";
			  print "(Try the 'help' command?)\n"; }
EOCMDS

my $shell = Getopt::Declare->new($shell_cmds,[-BUILD]);

my $count = 1;
sub prompt { print "$count> "; $count++; return <STDIN> }

print "Welcome to an interactive shell!\n";
$shell->parse(\&prompt);