Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Function - Return String
#!/bin/bash
function getUserInput()
{
#declare variables
local username_=""
#read data
read username_
#return variables
echo "$username_"
}
#greetings
echo "hello, who am I talking to..."
#get data
usernameRet_=$(getUserInput)
echo "The name entered is $usernameRet_"
#!/bin/bash
function getUserInput()
{
#declare a name reference
#The name reference should reference the first parameter
declare -n usernameref_=$1
#prompt user for his/her name
echo Hello, who am I talking to?
#accept name and place in name reference
read usernameref_
}
# Hello World Program in Bash Shell
username=''
getUserInput username
echo "Hello $username"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment