Project

General

Profile

« Previous | Next » 

Revision 290

env_password: Print instructions for storing password for the session

View differences:

env_password
2 2
# Sets a password environment variable
3 3

  
4 4
test "$#" -ge 1 || \
5
{ echo "Usage: . $0 env_var_name [msg] (note the initial \".\")" >&2; exit 2;}
5
{ echo "Usage: . $BASH_SOURCE env_var [msg] (note initial \".\")" >&2; exit 2;}
6 6

  
7 7
msg="$2"
8 8
test -n "$msg" || msg="$1"
9 9

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

  
10 15
if test -z "${!1+t}"; then # env var with name $1 is unset
16
    echo " To avoid having to reenter $msg password, run: " >&2
17
    trace . "$BASH_SOURCE" "$@"
11 18
    read -s -p "Enter $msg password: "; echo
12 19
    export "$1"="$REPLY"
13 20
fi

Also available in: Unified diff