Instead of using a grep to remove the current SSH_AUTH_SOCK, use a loop.
This commit is contained in:
parent
d63471c633
commit
dc550c2d59
1 changed files with 10 additions and 3 deletions
13
.bashrc
13
.bashrc
|
@ -67,15 +67,22 @@ _find_agent_sock() {
|
|||
}
|
||||
|
||||
_pop_agent_sock() {
|
||||
local IFS=$'\n' REPLY SOCKS=()
|
||||
local I IFS=$'\n' REPLY SOCKS=()
|
||||
# Read the current list of auth sockets.
|
||||
if ((${BASH_VERSINFO[0]} >= 4)); then
|
||||
mapfile -t SOCKS < <(egrep -v "^$SSH_AUTH_SOCK\$" ~/.ssh/agents 2>/dev/null)
|
||||
mapfile -t SOCKS <~/.ssh/agents
|
||||
else
|
||||
while read -r; do
|
||||
SOCKS+=("$REPLY")
|
||||
done < <(egrep -v "^$SSH_AUTH_SOCK\$" ~/.ssh/agents 2>/dev/null)
|
||||
done <~/.ssh/agents
|
||||
fi
|
||||
# Remove the last instance of the socket in $SSH_AUTH_SOCK.
|
||||
for ((I = (${#SOCKS[@]} - 1); I >= 0; I--)); do
|
||||
[[ "${SOCKS[$I]}" == "$SSH_AUTH_SOCK" ]] && {
|
||||
unset SOCKS[$I]
|
||||
break
|
||||
}
|
||||
done
|
||||
# Clean up any dead sockets - this modifies the SOCKS array.
|
||||
_clean_agent_socks
|
||||
# Write the new list back to disk.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue