Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Why does system("mv $x $y") not work when it works at the command line? (updated)

by haukex (Archbishop)
on Feb 03, 2023 at 04:58 UTC ( [id://11150115] : note . print w/replies, xml ) Need Help??


in reply to Why does system("mv $x $y") not work when it works at the command line?

First, you shouldn't be using system for that operation, you should be using Perl's builtin rename, or move from the core module File::Copy.

Second, if you ever do need to run an external command, see my node Calling External Commands More Safely.

Update: Additionally, when you run your Perl script from the command line, you need to properly escape/quote the filename (e.g. in single quotes) to prevent special characters in the filename (like the brackets) from being interpreted by the shell. Modern shells' tab completion can do this for you.