在 while 循环中回显 txt 中的每一行

在 while 循环中回显 txt 中的每一行

我正在编写一个简单的脚本,我提供一个列表,脚本输出以及商店的位置。但我在输出中遇到问题,因为我想要这个输出

echo "$stores location is $locations"
store1.com location is New York

但我得到这个回应

Processing store1.com
Processing store2.com
location is New York
location is Chicago
location is Phoenix
Processing store3.com

(我是新编程)

#!/bin/bash
if [ -z "$1" ]
    then
        printf "No file name specified\nExecute script.sh [NameOfFile]\n"
        exit
fi
now=$(date +"%m%d%Y%H%M")
fileName=Results_$now.txt

while read stores;
do
    echo "Processing $stores"
    locations=$(curl -silent https://mysite.com/location/$stores | grep -P -o 'Location.*?<div class="row">' | sed -e :a -e 's/<[^>]*>//g;/</N;//ba' | sed 's/./& - /12')
    
    echo "$stores location is $locations"
    echo -e "$stores location is $locations" >> $fileName
done < $1

相关内容