tags:

views:

148

answers:

2

$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

  • 10.0.40.177
  • 52335
  • 22

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.

+3  A: 
sshvars=($SSH_CLIENT)
echo "${sshvars[0]}"

or:

echo "${SSH_CLIENT%% *}"
Ignacio Vazquez-Abrams
+2  A: 

you can use set -- eg

$ SSH_CLIENT="10.0.40.177 52335 22"
$ set -- $SSH_CLIENT
$ echo $1  # first "element"
10.0.40.177
$ echo $2  # second "element"
52335
$ echo $3
22
ghostdog74