in reply to Unix command working with Perl
Update: note this code applies to any system calls, not just 'mv'. there are better tools for moving files, as mentioned by other monks.
Update: escaped backslash in regex#!/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! $!";
~Particle *accelerates*
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Unix command working with Perl
by Anonymous Monk on May 31, 2002 at 14:35 UTC | |
by Hofmator (Curate) on May 31, 2002 at 14:45 UTC | |
by particle (Vicar) on May 31, 2002 at 14:55 UTC |