check out the docs for
system. use the multiple argument form, and check the return code. also, use
taint mode to check the arguments for nasty surprises. the following code is untested...
Update: note this code applies to any system calls, not just 'mv'. there are better tools for moving files, as mentioned by other monks.
#!/usr/bin/perl -wT
use strict;
## check your arguments
@_ == 2 or die "Usage: $0 from to\n";
## specify your command
my $cmd = '/usr/bin/mv';
## untaint your input
my( $from ) = ( $ARGV[0] =~ s/(\w|[/\\])+/$1/ );
my( $to ) = ( $ARGV[1] =~ s/(\w|[/\\])+/$1/ );
## make sure the input is good
( defined $from and defined $to ) or die "ERROR: $0 - bad input\n";
## run the command without using the shell
## check return code for errors
system( $cmd, $from, $to ) or die "ERROR: $0 - can't $cmd! $!";
Update: escaped backslash in regex
~Particle *accelerates*
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.