help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-bash] Functions and interactive scripts


From: Richard Taubo
Subject: [Help-bash] Functions and interactive scripts
Date: Thu, 19 Mar 2015 11:20:53 +0100

Hi!

I was think about creating an interactive script and output the result
to a variable like this:
=========================
function ask_question() {
        printf "$1"
        read ANSWER
        printf "Answer: $ANSWER\n"
}

the_answer=$(ask_question "Are you happy?")
printf  "$the_answer"
=========================

This obviously does not work.
Do I need to use a global variable in such a case, or are there better options?
With global:
=========================
function ask_question() {
        printf "$1"
        read ANSWER
}

ask_question "Are you happy?"
the_answer=$ANSWER
ANSWER=""
printf  "Answer: $the_answer\n"
=========================


Thanks for input!

Richard Taubo


reply via email to

[Prev in Thread] Current Thread [Next in Thread]