, # Basic function , print_something () { , echo Hello I am a function , } , print_something , print_something , , # Basic function with parameters , test_function_1 () { , echo Hello I am a function $1 , } , test_function_2 () { , echo Hello I am function $1 , } , test_function_1 1 , test_function_2 two , , Return Values , Most other programming languages have the concept of a return value for functions, , a means for the function to send data back to the original calling location. , Bash functions dont allow us to do this. They do however allow us to set a return , status. Similar to how a program or command exits with an exit status which , indicates whether it succeeded or not. We use the keyword return to indicate , a return status. , , # Setting a return status for a function , print_something () { , echo Hello $1 , return 5 , } , print_something World , echo The previous function has a return value of $? , , # Setting a return value to a function , lines_in_file () { , cat $1 | wc -l , } , num_lines=$( lines_in_file $1 ) , echo The file $1 has $num_lines lines in it. , , # Setting a return value to a function , lines_in_file () { , cat $1 | wc -l , } , num_lines=$( lines_in_file $1 ) , echo The file $1 has $num_lines lines in it. , , # Create a wrapper around the command ls , ls () { , command ls -lh , } , ls ,