1

Unable to assign the SSH version number to a variable in bash. Running the below code, the output from "uname -a" is assigned to the variable "os", however the output from "ssh -v" appears in the terminal window but isn't assigned to the variable "ssh_v".

Confirmed this is happening on various versions of Solaris and Ubuntu and I have no idea why.

CODE:

#!/usr/bin/env bash

ssh_v=$(ssh -V)
printf "ssh_version = $ssh_v\n"

os=$(uname -a)
printf "OS_version = $os\n"

OUTPUT:

root@myserver:/usr/build/run# ./test.sh
Sun_SSH_2.4, SSH protocols 1.5/2.0, OpenSSL 0x100020bf
ssh_version =
OS_version = SunOS myserver 5.11 11.3 sun4v sparc sun4v
0

1 Answer 1

4

It looks like SSH is printing the version in stderr, not stdout. So you need to redirect stderr to stdout:

ssh_v=$(ssh -V 2>&1)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.