Reputation: 4310
I have the following script:
#!/bin/bash
for line in $('curl -s https://scans.io/data/rapid7/sonar.http/20141209-http.gz | zcat | head -n 1000 | dap json + select vhost + lines');
do
echo "$line\n"
done
For which I am trying to achieve the following:
However I'm getting syntax error near unexpected token
$'\r''` but am not a BASH expert to know what I need to tweak.
Upvotes: 3
Views: 6586
Reputation: 85530
Use Process-Substitution, with a while-loop, see why using for-loop for command output parsing is bad. The unsetting of IFS
and read
with the -r
flag does not allow backslashes to escape any characters and treat strings "as-is".
#!/bin/bash
while IFS= read -r line
do
printf '%s\n' "$line"
done < <(curl -s https://scans.io/data/rapid7/sonar.http/20141209-http.gz | zcat | head -n 1000 | dap json + select vhost + lines)
Upvotes: 5