0

I'm trying to run the bellow commands from a script:

eval $(ssh-agent -s)
ssh-add

The purpose behind them is to avoid being asked for my git passkey for the rest of the current session. Entering the commands one by one works ok and so I've put them in this script:

#!/bin/bash 

eval $(ssh-agent -s)
ssh-add

After running it I get the correct response from git:

$ gitnopasskey.sh
Agent pid 4260
Enter passphrase for /u/.ssh/id_rsa:
Identity added: /u/.ssh/id_rsa (/u/.ssh/id_rsa)

but I'm still being prompted for my key everytime I fetch, pull etc. I've copied the commands used in the script and entered them one by one, to make sure I'm typing the same commands, but the result is the same - it works when entering the commands, it doesn't work when running them from a script.

2
  • 1
    Scripts run in their own shell. Try sourcing the script instead: source gitnopasskey.sh. Otherwise all environment variables will be untouched in your parent shell (just like cd inside a script won't touch your parent's working directory) Commented Jul 22, 2015 at 11:01
  • That worked, thanks! Commented Jul 22, 2015 at 11:02

1 Answer 1

2

Scripts run in their own shell. Try sourcing the script instead:

source gitnopasskey.sh

Otherwise all environment variables will be untouched in your parent shell (just like cd inside a script won't touch your parent's working directory)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.