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

ベストアンサー1

おすすめ記事