Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capturing stdout into a variable

Tags:

bash

This might be a naive question, but I'm really not sure how to do it. I submit a spark job and I get the following output.

Run job succeeded. Submission id: driver-20170824224209-0001

I want to programmatically query the status of this job. How can I use the output in the console to extract the id to a variable using a bash script. Any help appreciated.

like image 318
Melissa Stewart Avatar asked Jun 14 '26 07:06

Melissa Stewart


1 Answers

Let's say you command is cmd and you want to store the output of the command in ( say ) a variable called res, one way in bash is to run the command in single quotes

res=`cmd`

or embed the command within $()

res=$(cmd)

Capture both stdout and stderr in Bash

like image 154
asio_guy Avatar answered Jun 17 '26 23:06

asio_guy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!