0

I'm trying to assign the output of awk to variable. I tried with solutions specified here but nothing seems to work. I'm first doing curl and then parsing the result from there

#!/bin/sh 

KEY="title"

curl https://jsonplaceholder.typicode.com/todos/1 | statu=$(awk -F'[,:}]' 
'{for(i=1;i<=NF;i++){if($i~/'$KEY'\042/){print $(i+1)}}}'  | tr -d '"')

echo "This is status" "$statu"

1 Answers1

0

You should use command substitution like follows:

#!/bin/sh 

KEY="title"

statu=$(curl https://jsonplaceholder.typicode.com/todos/1 | awk -F'[,:}]' 
'{for(i=1;i<=NF;i++){if($i~/'$KEY'\042/){print $(i+1)}}}'  | tr -d '"')

echo "This is status" "$statu"
mik1904
  • 1,335
  • 9
  • 18