如何避免连接字符串时跳转线消失

如何避免连接字符串时跳转线消失

我想列出我的项目的所有文件中包含的所有 URL。

第一个功能find_url_in_file,运行良好 --> 我有这个列表

https://www.example.com/en/docs/console/my-project/how-to/add-resources-project
https://www.example.com/en/docs/console/my-project/how-to/generate-api-key
https://www.example.com/en/docs/console/my-project/how-to/delete-a-project
https://www.example.com/en/docs/console/my-project/how-to/join-an-organization

然后使用第二个函数find_all_url_in_file,当它连接时,它会删除所有行跳转:

https://www.example.com/en/docs/console/my-project/how-to/add-resources-projecthttps://www.example.com/en/docs/console/my-project/how-to/generate-api-keyhttps://www.example.com/en/docs/console/my-project/how-to/delete-a-projecthttps://www.example.com/en/docs/console/my-project/how-to/join-an-organization

我想保留此换行符以获得一个简单干净的列表。我该怎么做?(也许使用临时文件是个更好的主意?)

all_mdx_file=$(find_all_mdx)

find_url_in_file(){
    local file="${1}"
    local url_list=""
    grep -Eo '(http|https)://www.xxxxxx.com[^ )>"]+' $file || : | \
    while IFS= read -r url; do 
        url_list+="$url"
    done
    echo "$url_list"
}

find_all_url_in_file(){
    local file="${1}"
    local list_url=""
    while IFS= read -r mdx; do 
        # echo "mdx read : $mdx"
        url_in_this_file=$(find_url_in_file $mdx )
        list_url+="$url_in_this_file "
    done <<< "$file"
}

find_all_url_in_file "$all_mdx_file"

相关内容