user873286
user873286

Reputation: 8099

Bash Last Carriage character, newline character stripping

I have the following bash script:

#!/bin/bash

FILE="p.txt"
while read line; do
    export http_proxy="http://$line"
    wget http://www.example.com
done < $FILE

the problem is, it gives the following error:

http://80.251.247.14:3128
: Bad port number.y URL http://80.251.247.14:3128

I think it is because of last character, either it is newline \n or \r, how can I fix this?

Upvotes: 3

Views: 280

Answers (1)

perreal
perreal

Reputation: 98108

You can use tr -d '\n':

while read line; do
    export http_proxy=$(echo "http://$line" | tr -d '\n')
    wget http://www.example.com
done < $FILE

Upvotes: 3

Related Questions