chbarros chbarros - 7 months ago 10
Perl Question

perl -le inside parens doesn't working in bash script

I'm using a script to run a content from a text file with a perl command. It is inside parentheses and is showing command not found. I tried to include this line to a variable and execute by $() or ${variable} but the return is always "(: command not found"

#!/bin/bash
...
( perl -le 'print "test"' && cat example.txt) > example2.txt || ( rm -rf example2.txt && false )

Answer

The code you posted does not exhibit the behaviour you claim.

$ cat a.bash
#!/bin/bash
( perl -le 'print "test" && cat example.txt) > example2.txt || ( rm -rf example2.txt && false )

$ ./a.bash
./a.bash: line 2: unexpected EOF while looking for matching `''
./a.bash: line 3: syntax error: unexpected end of file

$

After adding the missing ':

$ cat a.bash
#!/bin/bash
( perl -le 'print "test"' && cat example.txt) > example2.txt || ( rm -rf example2.txt && false )

$ ./a.bash

$