diff options
| author | Gabe Berke-Williams <gbw@brandeis.edu> | 2011-01-01 15:28:54 -0800 |
|---|---|---|
| committer | Gabe Berke-Williams <gbw@brandeis.edu> | 2011-01-01 15:28:54 -0800 |
| commit | 25c4555104615f9db381ec8310b3d737714b2efb (patch) | |
| tree | 0594f13e839872c6f455a28cb2f84bc4e086c00d | |
| parent | c269c3c0fc4039676b8f6b2e256530df57754547 (diff) | |
Quote bash variables and ensure file existence
Ensure filenames with spaces don't make the sample script choke
| -rw-r--r-- | _posts/2009-09-03-working-with-key-passphrases.textile | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/_posts/2009-09-03-working-with-key-passphrases.textile b/_posts/2009-09-03-working-with-key-passphrases.textile index 988e66b..c168c84 100644 --- a/_posts/2009-09-03-working-with-key-passphrases.textile +++ b/_posts/2009-09-03-working-with-key-passphrases.textile @@ -42,10 +42,10 @@ SSH_ENV="$HOME/.ssh/environment" function start_agent { echo "Initializing new SSH agent..." # spawn ssh-agent - ssh-agent | sed 's/^echo/#echo/' > $SSH_ENV + ssh-agent | sed 's/^echo/#echo/' > "$SSH_ENV" echo succeeded - chmod 600 $SSH_ENV - . $SSH_ENV > /dev/null + chmod 600 "$SSH_ENV" + . "$SSH_ENV" > /dev/null ssh-add } @@ -63,14 +63,18 @@ function test_identities { } # check for running ssh-agent with proper $SSH_AGENT_PID -ps -ef | grep $SSH_AGENT_PID | grep ssh-agent > /dev/null -if [ $? -eq 0 ]; then - test_identities +if [ -n "$SSH_AGENT_PID" ]; then + ps -ef | grep "$SSH_AGENT_PID" | grep ssh-agent > /dev/null + if [ $? -eq 0 ]; then + test_identities + fi # if $SSH_AGENT_PID is not properly set, we might be able to load one from # $SSH_ENV else - . $SSH_ENV > /dev/null - ps -ef | grep $SSH_AGENT_PID | grep ssh-agent > /dev/null + if [ -f "$SSH_ENV" ]; then + . "$SSH_ENV" > /dev/null + fi + ps -ef | grep "$SSH_AGENT_PID" | grep ssh-agent > /dev/null if [ $? -eq 0 ]; then test_identities else |
