Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

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

by hv (Prior)
on Feb 03, 2023 at 03:04 UTC ( [id://11150111] : 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?

The shell will normally treat [xyz] as a character class, and attempt to match filenames on that basis. But if it finds no file matches for the expansion, it will instead pass the original characters as the argument:

% ls t0 t1 % echo t[012] t0 t1 % echo t[xy] t[xy] %

It isn't entirely clear to me what your filename is, or what your code is doing, but I suspect the shell behaviour is causing the confusion.

Replies are listed 'Best First'.
Re^2: Why does system("mv $x $y") not work when it works at the command line?
by Fletch (Bishop) on Feb 03, 2023 at 14:47 UTC

    This varies by shell. By default zsh will gripe if it can't find a match (although I think there's options enabled with setopt which will make it behave more like POSIX/ksh). For example the first works (because of course there's a file named foo . . . who doesn't have one?) but the second errors first and doesn't actually run the echo command.

    oscar:~ 1064> echo fo[ob] foo oscar:~ 1065> echo fo[xy] zsh: no matches found: fo[xy]

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.