InterviewSolution
Saved Bookmarks
| 1. |
How can we create a function in shell script? |
|
Answer» In other programming languages, shell FUNCTIONS are much like subroutines, procedures, and functions. The syntax for declaring a function is as FOLLOWS: function_name () { list of commands}Function_name is the name of your function, and that's what you'll use to call it from anywhere in your script. The function name must be followed by PARENTHESES, then a list of commands enclosed in braces. Example: The FOLLOWING example shows how function can be used: #!/bin/sh# Define your function here Hello () { echo "Hello World" } # Invoke your functionHelloThe following output will be displayed after execution: $./test.shHello World |
|