Search code examples
perlbackticksdig

Why does my Perl backticks complain "sh: line 1: any: command not found"?


I've never programmed before, but needed to write a very simple webapp for work.

I'm trying to get this dig query to work:

dig @8.8.8.8 +nocomments +nostats +noquestion +nocmd google.com any

With this bit of perl:

$dig = `/usr/bin/dig \@8.8.8.8 +nocomments +nostats +noquestion +nocmd $query any`;

Except it doesn't seem to recognize "any" at the end of dig and gives me:

sh: line 1: any: command not found

What stupidly simple thing am I doing incorrectly?


Solution

  • I bet $query has a newline in it, causing your shell to see any as a new command.

    Try doing chomp $query; before your system call to remove the newline. More on chomp.