in reply to Unix shell ls vs readdir

On some systems the output from "ls -l" may contain ANSI escape sequences, so it might be safer to use "\ls -l" instead.

Replies are listed 'Best First'.
Re^2: Unix shell ls vs readdir
by almut (Canon) on May 11, 2010 at 00:37 UTC
    it might be safer to use "\ls -l" instead

    Under almost all circumstances, the backslash would not be needed.  On the interactive command line, the backslash prevents alias expansion (such as "ls" —> "ls --color=auto", which then produces the ANSI escape sequences), because alias lookup happens before backslash escapes are processed, and there is no alias for "\ls".

    However,

    1. alias expansion is only done for interactive shells, and not for sh -c ... (i.e. qx{...} ) — unless explicitly requested otherwise,
    2. alias expansion would be done by the shell, but unless there are any shell metacharacters in the command, no shell is involved anyway, as Perl will run ls directly.

      True. I tend to forget that the shell is not involved.