my_kinit () {
# Interactively kinit if we don't find a tgt. Loop until successful or
# canceled.
local spn="$1" # Service principal name with which to kinit, e.g., 'name' or
# 'name@REALM'.
klist -s || {
local -i exit_status=1
until [[ $exit_status -eq 0 ]]; do
kinit "$spn" || {
local keypress=''
# The $ in the next line causes the string to evaled for substitution.
read -s -n1 -p $'Press c to cancel. Any other key to try again.\n' \
keypress
[[ $keypress = c ]] && return 1
}
done
}
}