How to do it...

We are going to write a simple function in our shell script to return the current date and time. Create a script function_example.sh, and write this code in it:

#!/bin/bashprint_date(){echo "Today is `date`"return}print_date

Now we will create another script containing two functions with the same name. Create a script function2.sh, and write the following content in it.

#!/bin/bashdisplay ( ) {echo 'First Block'echo 'Number 1'}display ( ) {echo 'Second Block'echo 'Number 2'}displayexit 0

Get Bash Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.