J
J
Just Pixel2019-07-01 14:04:29
linux
Just Pixel, 2019-07-01 14:04:29

Is it possible in BASH to assign to a variable the result of executing CURL with a query containing another variable?

There is a task: there is a document in which set of lines. It is necessary to loop through all the lines from the file, each line must be used as part of the URL that is accessed when using CURL. We would also like to assign the result of the server execution to a variable, since the result must be processed and saved as a file.

#!/bin/bash
FILE=$1
while read LINE; do
     RESULT=$(curl https://domain.com/get?foo1=$LINE)
     echo "Это строка: $LINE & $RESULT"
done < $FILE

I've tried adding the LINE variable in many ways, but always managed to either use the variable in CURL, or assign the result of CURL execution to a variable, but never managed to match. I'm a Windows user and far from bash, so I thought I'd ask the community for help.
Thanks in advance for any help on the issue.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
CityCat4, 2019-07-01
@Z-StyLe

#!/bin/bash
FILE=$1
while read LINE; do
     bla=`curl https://domain.com/get?foo1=$LINE`
     RESULT=eval $bla
     echo "Это строка: $LINE & $RESULT"
done < $FILE

D
Dmitry Shitskov, 2019-07-01
@Zarom

RESULT=$(curl "https://domain.com/get?foo1=${LINE}")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question