filmov
tv
#ShellScript: How to write #functions? | Nested functions

Показать описание
A #simple example which demonstrates #shell #script with #functions.
Functions :
Functions make #scripts easier to maintain. Basically, it breaks up the program into smaller pieces. A function performs an action defined by you, and it can return a value if you wish.
src code:
#!/bin/sh
# 1.
# function function_name () {
# commands;
# }
# 2.
# function_name () {
# commands;
# }
# Example to demonstrate functions within a shell script.
fun3 () {
echo "This is fun3().";
}
fun2 () {
echo "This is fun2().";
fun3;
}
function main () {
echo "This is main()";
fun2;
echo "End of main()";
}
main;
exit 0;
Functions :
Functions make #scripts easier to maintain. Basically, it breaks up the program into smaller pieces. A function performs an action defined by you, and it can return a value if you wish.
src code:
#!/bin/sh
# 1.
# function function_name () {
# commands;
# }
# 2.
# function_name () {
# commands;
# }
# Example to demonstrate functions within a shell script.
fun3 () {
echo "This is fun3().";
}
fun2 () {
echo "This is fun2().";
fun3;
}
function main () {
echo "This is main()";
fun2;
echo "End of main()";
}
main;
exit 0;