Johns Simon
Johns Simon

Reputation: 19

store the generated output into variables in shell scripting

How to store the output generated by a curl request into variables

m=$(curl  -b cookiez.txt -L http://bmcassistant.org/webac/Department/Student/CurrentSemesterDetails.aspx?|grep -o 'href=.*>.*%' | grep -o '>.*%'|sed 's/>//') 

echo $m>>attendance.txt

Output of attendance.txt

10% 80% 50% 100%

I want to store these numbers into variables like m,n,o,p So i can call it later in shell script by referencing them by $m,$n,$o,$p

Upvotes: 0

Views: 32

Answers (1)

dvenkatsagar
dvenkatsagar

Reputation: 936

I think this should do the trick:

while IFS='' read -r line || [[ -n "$line" ]]; do
  read -a arr <<< $line
  echo ${arr[@]}
done < "attendance.txt"

Change the @ for the different values.

Instead of reading the txt file again, as you have $m which has the string, you can simply do this:

read -a arr <<< $m

Upvotes: 1

Related Questions