Bash 在同一文件夹中的txt文件中使用日志和参数进行卷曲
我正在构建一个.sh脚本,以根据放置在文件fileWithItems.txt中的项目(每行)运行curls。 这是我构建的脚本:Bash 在同一文件夹中的txt文件中使用日志和参数进行卷曲,bash,curl,sh,Bash,Curl,Sh,我正在构建一个.sh脚本,以根据放置在文件fileWithItems.txt中的项目(每行)运行curls。 这是我构建的脚本: declare -a array #assuming fileWithItems.txt contains one element per line to be used in the url is in the same folder as this .sh mapfile -t array < fileWithItems.txt host="localhos
declare -a array
#assuming fileWithItems.txt contains one element per line to be used in the url is in the same folder as this .sh
mapfile -t array < fileWithItems.txt
host="localhost"
port="PORT"
i=0
while [ ${i} -lt ${#array[@]} ] ; do
curl -X PUT "$host:$port/path1/${array[$i]}/refresh" > log.txt
((i++))
done
declare-a数组
#假设fileWithItems.txt在url中使用的每行包含一个元素与此.sh在同一文件夹中
mapfile-t数组log.txt
((i++)
完成
似乎卷曲没有被正确地构建。如何优化它?要从我的评论中进一步阐述,您可以这样做:
host="localhost"
port="PORT"
while IFS= read -r line; do
curl -X PUT "$host:$port/path1/$line/refresh"
done < fileWithItems.txt > log.txt
host=“localhost”
port=“port”
而IFS=读取-r行;做
curl-X放置“$host:$port/path1/$line/refresh”
完成log.txt
请注意
>log.txt
在完成后的位置,这样您就不会每次都覆盖同一个文件。要从我的评论中进一步阐述,您可以这样做:
host="localhost"
port="PORT"
while IFS= read -r line; do
curl -X PUT "$host:$port/path1/$line/refresh"
done < fileWithItems.txt > log.txt
host=“localhost”
port=“port”
而IFS=读取-r行;做
curl-X放置“$host:$port/path1/$line/refresh”
完成log.txt
请注意>log.txt
在完成后的位置,以免每次都覆盖同一个文件。有什么错误?顺便说一句,您不需要构建阵列。只要在while循环中读取文件,并为每一行调用curl
。@anubhava hmmm不知道这是可能的。但我需要从每一行得到一个字符串,并把它放在卷曲字符串的中间。错误是什么?顺便说一句,您不需要构建阵列。只要在while循环中读取文件,并为每一行调用curl
。@anubhava hmmm不知道这是可能的。但我需要从每一行得到一个字符串,并把它放在卷曲字符串的中间。