Brad Parks
Brad Parks

Reputation: 72283

Capture output of curl sub shell?

I've got a curl command like so:

curl -v --silent --tlsv1.1 https://google.com/ 2>&1 | grep TLS

I'd like to capture the output of that command in a variable. Normally I'd use a subshell to do this, but it doesn't seem to work.

Here's what I'm trying to do:

OUT=$(curl -v --silent --tlsv1.1 https://google.com/ 2>&1 | grep TLS)
echo $OUT

but the command outputs the following (if I'm in a directory with a single file in it called "UNEXPECTED.TXT").

UNEXPECTED.TXT TLS 1.0 connection using TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA

So it seems to do a directory listing of the current directory, then append my output to the end of that.

Thanks!

Upvotes: 2

Views: 649

Answers (1)

anubhava
anubhava

Reputation: 786071

Use quotes:

echo "$OUT"
* TLS 1.1 connection using TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA

Since variable OUT has a starting *, without quotes shell is expanding first * to all the files/directories in your current path and listing all the files/directories.

Upvotes: 2

Related Questions