1. Define functions within the shell file and refer to:
Copy Code code as follows:
[~/shell/function]# Cat factorial.sh
#!/bin/bash
function factorial
{
Factorial=1
For ((I=1;i Todo
factorial=$[$factorial * $i]
Done
function allows us to divide a complex function into several modules, which makes the program structure clearer and the code reuse more efficient. Like other programming languages, the Shell supports functions as well. The Shell function must be
Linux Shell series (15th) Shell function introduction, linuxshell
This article is part 15 of the Linux Shell series. For more Linux Shell series tutorials, see: Linux Shell series tutorials.A function can divide a complex function into several
function allows us to divide a complex function into several modules, which makes the program structure clearer and the code reuse more efficient. Like other programming languages, the Shell supports functions as well. The Shell function must be
The first Unix Shell function has a beginning for everything. There is a saying that it is difficult to start with everything. No matter how the road goes, take every step at your feet. Today, I got started with Unix shell functions and wrote a
The Shell function returns the value, generally has 3 kinds of ways: Return,argv,echo
1) Return statementThe return value of the Shell function, as in other languages, can be returned through the return statement.Example:
The Linux shell can be user-defined functions and can be called casually in shell scripts.The functions in the shell are defined in the following format:[Function] funname [()]{Action[Return int;]}Description1, can be with function fun () definition,
First, function definitionThe Linux shell can be user-defined functions and can be called casually in shell scripts.The functions in the shell are defined in the following format:function ] Funname [()]{ action; int ;]}Description
1,
Shell function return value, generally in three ways: return, argv, Echo
1) Return StatementThe Return Value of the shell function, which can be the same as that of other languages, returned through the return statement.Example:
#!/bin/bash
function allows us to divide a complex function into several modules, which makes the program structure clearer and the code reuse more efficient. Like other programming languages, the Shell supports functions as well. The Shell function must be
Important notes about the function:When executing the Shell function, the function name and the parentheses after the function name are not required;The definition of a function must be defined or loaded before the executing programThe execution
This example mainly realizes the function that VB calls the external EXE program to run, this is mainly uses the Shell function to execute, the shell function is mainly used to open an external exe executable file, for example, in sub module: Shell "
Shell function-based usage tries to find all the configuration file content in each program directory in a loop function www.2cto.com #. the parameter is the name of the file to be processed and the function to be processed whilefun () # arg1file $1,
Shell entry: Shell function and file redirection, shell redirectionShell entry (5) Shell functions and file redirection Shell functions
Shell Function Definition:
[ function ] funname [()]{ action; [return int;]}
DescriptionYou can use
Shell function calls are divided into two types:The first way, a bit like the C language Call function style, directly to the function of the execution of the result copy to the variable! However, the assignment process is not the same as the C
1. Gets the return value of the Shell function call:#!/bin/sh info () { cat jlb.sh} res= ' info ' echo ' state: ' $?echo ' res: ' ${res}description : res='info' This behavior calls function info, which conforms to ' not single quotes, but the
Ext.: http://blog.csdn.net/ithomer/article/details/7954577Shell function return value, generally there are 3 ways: Return,argv,echo1) Return statementThe return value of the Shell function, which can be returned by a return statement, as the return
The Shell also supports functions. The Shell function must be defined before use.The Shell functions are defined in the following format:Function_name () { List of commands [return value]}If you prefer, you can also add keyword functions to
1. Gets the return value of the Shell function call:#!/bin/sh info () { cat jlb.sh} res= ' info ' echo ' state: ' $?echo ' res: ' ${res}description : res='info' This behavior calls function info, inside the symbol ' is not a single argument,
The Linux shell can be user-defined functions and can be called casually in shell scripts.
The functions in the shell are defined in the following format:
[Function] funname [()]
{
action;
[return int;]
}
Description
1, can be with function fun
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.