I want to run this command in perl
for dir in *; do
test -d "$dir" && ( find "$dir" -name '*test' | grep -q . || echo "$dir" );
done
I have tried :
system ("for dir in *; do
test -d "\$dir" && ( find "\$dir" -name '*test' | grep -q . || echo "\$dir" );
done");
but does not work .
Your quoting is off.
You have decided to delimit your string with double quotes
", but they are included in your string.Either escape the other quotes:
(error prone, ugly)
… or use another delimiter: Perl offers you a wide range of possibilities. These quoting syntaxes interpolate variables inside:
"…"andqq{…}where you can use any character in[^\s\w]as delimiter, and non-interpolating syntaxes are:'…'andq{…}with the same delimiter flexibility as before:The
qandqqconstructs can include the delimiter inside the string, if the occurrence is balanced:q( a ( b ) c )works.The third quoting mechanism is a here-doc:
This is usefull for including longer fragments without worrying about a delimitor. The String is ended by a predefined token that has to appear on a line of its own. If the delimitor declaration is placed in single quotes (
<<'END_OF_SCRIPT'), no variables will be interpolated:Note on the
q{}andqq{}syntax: This is a feature never to be used outside of obfuscation, but it is possible to use a character in\was the delimiter. You have to include a space between the quoting operatorqorqqand the delimiter. This works:q xabcxand is equal to'abc'.