I have a script with the following body:
FILE_NAME=$(getFileToImport)
echo Your file is $FILE_NAME
The function getFileToImport
is made to ask the user to choose a file, then the function itself will work it out a bit, and I would like to store the name of this newly created file into the variable FILE_NAME
.
The function looks like something like this:
getFileToImport()
{
echo Give me a name for your file:
read FILE_NAME
#Some fancy stuff here
echo $FILE_NAME
}
If I do the above, I will never see the echos of the function (saying "Give me a name for your file"), so the function will directly go into the read
statement without giving instructions to the user.
If I just invoke the function, meaning:
getFileToImport
instead of
FILE_NAME=$(getFileToImport)
... everything will work but I won't have FILE_NAME
set to be used in the rest of the script.
How can I make my function returning me a value but still keeping on showing the interactive part (echos
and reads
) to the user so that they know what to do?