How can I use bash syntax in Perl’s system() command?
I have a command that is bash-specific, e.g. the following, which uses bash’s process substitution:
diff <(ls -l) <(ls -al)
I would like to call it from Perl, using
system('diff <(ls -l) <(ls -al)')
but it gives me an error because it’s using sh instead of bash to execute the command:
sh: -c: line 0: syntax error near unexpected token `(' sh: -c: line 0: `sort <(ls)'
Tell Perl to invoke bash directly. Use the
listvariant ofsystem()to reduce the complexity of your quoting:You may even define a subroutine if you plan on doing this often enough: