'...">

How to capture curl output into a variable in bash

So, let's say I have the following command:

curl -I http://google.com | head -n 1| cut -d $' ' -f2 

This will display the status code http ?? Now I want to assign this to a variable .. in a bash script

 like output = "curl -I http://localhost:8088/tracks?key=9 | head -n 1| cut -d $' ' -f2" 

or something like that.

How to assign the response of the above command to a variable called output in bash? Thanks

+6
source share
1 answer

You have two options . Surrounding the call in reverse tick or $() , like this:

 output=`curl -I http://google.com | head -n 1| cut -d $' ' -f2` echo $output; output=$(curl -I http://google.com | head -n 1| cut -d $' ' -f2) 
+17
source

Source: https://habr.com/ru/post/973852/


All Articles