in reply to A looping question
A decent command-line shell offers things like path-name completion (type a few characters and hit the tab key), and command history with easy recall(/edit)/rerun of previous commands, to minimize the amount of typing needed.
IMHO, the start of your script should just be:
That way, if the person typed an existing path name by mistake, they just recall, edit and rerun the command line. If they already know that the existing path name should be deleted/replaced, they include "-f" on the command line. Now, the operation can be run as part of in any shell script (or another perl script), and can run without manual intervention (e.g. as a scheduled task).use strict; use warnings; my $Usage = "Usage: $0 [-f] directory_path\n"; my $force; if ( @ARGV > 1 and $ARGV[0] eq '-f' ) { $force = shift; } die $Usage unless ( @ARGV == 1 ); my $dirname = shift; if ( -e $dirname and ! $force ) { die "$dirname exists. Use '-f' option to delete the existing $dir +name\n$Usage"; } ...
If there are other run-time user decisions to be handled, which should be provided by means of additional command-line options, then you'll want to get acquainted with Getopt::Long or Getopt::Std (which come as core modules with Perl).
|
|---|