Post

Shell Terminal - save credentials in env var

Sometimes I need to save credentials in an environment variable that I can later use in a script.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# prompt for user for username.
read -s -p "Enter username: " SECRET_USER
# User types the username

# export as env var
export SECRET_USER

# prompt user for password
read -s -p "Enter password: " SECRET_PASSWORD
# User types the username

# export as env var
export SECRET_PASSWORD

# use in script
curl --user $SECRET_USER:$SECRET_PASSWORD $etc

References

  • Helpful link: https://stackoverflow.com/a/3980904
This post is licensed under CC BY 4.0 by the author.