So I have this peace of bash code to execute nmap command with different arguments in $line variable

When I transform it into an in-line command it works perfectly with separated arguments from $line, but in a script, it takes what's in $line as one argument

Not sure if it's an Nmap issue or a bash issue but since it worked in command line i believe it's a bash issue

Any ideas would be appreciated, thanks!

function feedToNmap() {
        while read line
                nmap $line >> nmap_out
        done < nmap_input
  • 1
    I assume you have copied the script code verbatim i.e. not omitted any use of quoting in the script or in nmap_input Try read -a line and nmap ${line[@]} Jun 21, 2020 at 11:06
  • Are you sure you didn't do nmap "$line" >> nmap_out? Jun 21, 2020 at 14:23
  • ... or perhaps you are using a different shell such as zsh in which unquoted variable expansions do not undergo word splitting by default? Jun 21, 2020 at 15:45
  • change the field separator IFS and read delimiter -d into whitespace otherwise each line is one $line for \n
    – alecxs
    Jun 21, 2020 at 15:54

1 Answer 1


Thanks guys, turned out to be a weird issue

I was adding to an array before this function with something like this: array <<< elements (i dont remember the exact line)

Apparently the three <<< missed up the code that comes after for some reason, idk why but I worked it around by adding to the array without <<<

  • It would be better to quote your actual wrong code, and the corrected code, and then to say why the corrected code works while the wrong code does not. You can't create an array with <<< directly.
    – Kusalananda
    Jun 22, 2020 at 15:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .