I'm doing a simple script that I provide a list and the script outputs with the location of the store. But I have problems in the output because I want this output
echo "$stores location is $locations"
store1.com location is New York
But I get this as response
Processing store1.com
Processing store2.com
location is New York
location is Chicago
location is Phoenix
Processing store3.com
(Im new programming)
#!/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
locations=$(curl ...) & waitto ensure that setting the location variable is done before the next step.waitpretty much does what the command's name suggests, for more info, useman wait.& waitin thelocations=-line. Did you try that?wait... a background process does not work for assigning variables.