Project

General

Profile

1
#!/bin/bash
2
# Sets a password environment variable
3

    
4
self="$(readlink -f -- "$BASH_SOURCE")"
5

    
6
test "$#" -ge 1 || \
7
{ echo "Usage: . $self env_var_name [msg] (note initial \".\")" >&2; exit 2;}
8

    
9
msg="$2"
10
test -n "$msg" || msg="$1"
11

    
12
function trace()
13
{
14
    { for arg in "$@"; do printf "%q " "$arg"; done; echo;} >&2
15
}
16

    
17
if test -z "${!1+t}"; then # env var with name $1 is unset
18
    echo " To avoid having to reenter $msg password, run: " >&2
19
    trace . "$self" "$@"
20
    read -s -p "Enter $msg password: "; echo
21
    export "$1"="$REPLY"
22
fi
(2-2/14)