#!/bin/bash

fun_get_user_variables_no_default(){

get REMOTE_SERVER_EMAIL, if not supplied, quit. No default.

The line VARIABLES=("${!1}") in Bash is used to create an array called VARIABLES

that gets its values from the positional parameter specified by $1, where $1 is

the first argument passed to the function or script.

local VARIABLES=("${!1}")

local: This declares a local variable within a function

while ${1} represents the value of the first positional argument passed to a script or function.

local TMP_DEFAULT local TMP_USER local TMP_READ

echo "Automatic timeout is 120 sec"

for i in ${VARIABLES[@]}; do TMP_DEFAULT=DEFAULT_$i echo -n "GIMMME the $i (username, eg: ${!TMP_DEFAULT}), no default value:" read -t 120 TMP_READ echo "" declare -g USER_$i=$TMP_READ TMP_USER=USER_$i

if [ "${!TMP_USER}" == "" ]; then echo -n "${TMP_USER} can not be empty. Please give it again:" read -t 130 TMP_READ declare -g USER_$i=$TMP_READ TMP_USER=USER_$i if [ "${!TMP_USER}" == "" ]; then echo "Second try failed. Quitting..." exit 1 fi fi done

}

export -f fun_get_user_variables_no_default

fun_get_user_variables_no_default alexlai 1234