Subject: bash like array in ksh? or alt?
To: None <netbsd-users@netbsd.org>
From: George Georgalis <george@galis.org>
List: netbsd-users
Date: 01/15/2007 22:25:25
I need to run something like this bash code in
.profile for ksh.

if [ -f ~/.ssh/id_dsa -o -f ~/.ssh/id_rsa  -o -f ~/.ssh/identity ]; then
        printf "${USER}@${HOSTNAME}: "
        eval `ssh-agent`
        SSH_AGENT_SHELL_PID=([$$]=${SSH_AGENT_PID})
        ssh-add \
                || { kill $SSH_AGENT_PID
                        unset SSH_AGENT_PID SSH_AGENT_SHELL_PID[$$] ;}
fi


after it tests for interactive session it prompts
to startup ssh-agent for any child processes, if an
agent is not already running.

Then on logout, only closing the shell ($$) that opened the agent
will kill the agent.

# ~/.bash_logout
sshpid=${SSH_AGENT_SHELL_PID[$$]}
[ -n "$sshpid" ] \
        && { kill "$sshpid" \
                || echo '~/.bash_logout: ssh-agent already died?' 2>/dev/stderr ;}


so for any shell where there is no agent running,
users are prompted to start one, then on clean
exit, the agent is killed. I'd like to port this to
ksh... but arrays aren't the same and I don't see an
immedate solution.


       ksh(1)
       ...The later form can be treated
       as arrays by appending an array index of the form: [expr] where expr is
       an arithmetic expression.  Array indices are currently limited  to  the
       range 0 through 1023, inclusive.

s there some hack that will allow me to kill
SSH_AGENT_SHELL_PID[$$] (if set) where the index is
0 to 65535 (presumed range of pids).

// George


-- 
George Georgalis, systems architect, administrator <IXOYE><