$SSH_CLIENT has IP address with some port info, and echo $SSH_CLIENT gives me '10.0.40.177 52335 22', and Running
if [ -n "$SSH_CONNECTION" ] ;
then
for i in $SSH_CLIENT
do
echo $i
done
fi
gives me
And I see the first element is the IP address.
Q : How can I get the first element of $SSH_CLIENT? ${SSH_CLIENT[0]} doesn't work.
sshvars=($SSH_CLIENT)
echo "${sshvars[0]}"
or:
echo "${SSH_CLIENT%% *}"
For strings, as is the case here, the <<<
operator may be used:
$ read ipaddress outport inport <<< $SSH_CLIENT
See e.g: Linux Bash: Multiple variable assignment. Don't do this with binary input though: Is there a binary safe <<< in bash?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With