Improve bash syntax

This commit is contained in:
John Mertz 2023-07-06 12:16:20 -04:00
parent e5cab9fa7e
commit f4c62a26a6
1 changed files with 8 additions and 8 deletions

View File

@ -1,17 +1,17 @@
#!/bin/bash #!/bin/bash
if [ -e $HOME/.spool/ssh-agent.sock ]; then if [ -e "${HOME}/.spool/ssh-agent.sock" ]; then
PID=$(tail -n 1 $HOME/.spool/ssh-agent.env | sed 's/echo Agent pid \([0-9]*\);/\1/') PID=$(tail -n 1 "${HOME}/.spool/ssh-agent.env" | sed 's/echo Agent pid \([0-9]*\);/\1/')
if [ -z $PID ]; then if [ -z "$PID" ]; then
pkill ssh-agent pkill ssh-agent
rm $HOME/.spool/ssh-agent.* rm "${HOME}/.spool/ssh-agent.sock" "${HOME}/.spool/ssh-agent.pid"
else else
CMD=$(ps -p $PID -o comm | tail -n 1) CMD=$(ps -p "$PID" -o comm | tail -n 1)
if [ ! -z $CMD ] && [ $CMD == 'ssh-agent' ]; then if [ -n "$CMD" ] && [ "$CMD" == 'ssh-agent' ]; then
echo "Valid agent already found at $HOME/.spool/ssh-agent.sock with PID $PID" echo "Valid agent already found at ${HOME}/.spool/ssh-agent.sock with PID $PID"
exit exit
fi fi
fi fi
fi fi
eval $(ssh-agent -a $HOME/.spool/ssh-agent.sock | tee $HOME/.spool/ssh-agent.env) >/dev/null eval $(ssh-agent -a "${HOME}/.spool/ssh-agent.sock" | tee "${HOME}/.spool/ssh-agent.env")