gpt4 book ai didi

linux - Bash Last Carriage 字符,换行符剥离

转载 作者:太空狗 更新时间:2023-10-29 11:10:37 25 4
gpt4 key购买 nike

我有以下 bash 脚本:

#!/bin/bash

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

问题是,它给出了以下错误:

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

我认为这是因为最后一个字符,它是换行符\n 或\r,我该如何解决这个问题?

最佳答案

您可以使用tr -d '\n':

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

关于linux - Bash Last Carriage 字符,换行符剥离,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9486949/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com