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 the function name:function function_name () { List of commands [ret
Label:Several cases of sqlplus and shell passing value to each other Scenario One: The simplest invocation of sqlplus in the shell $cat test.sh #!/bin/sh Sqlplus Oracle/[email Protected]>file.log SELECT * from Test; Exit EOF #注意EOF要顶格写 $sh test.sh $cat File.log --Omit a number of system prompt information------- Sql> EMPNO EmpName SAL DEPTNO -------------------
Using variables from the shell in awk
One: "' $var '"
In this way, you don't have to change the habit of using the AWK program, which is commonly used by foreigners. Such as:
var= "Test"
awk ' begin{print ' $var ' "} '
This notation is actually a constant that is double-parenthesis into parentheses, passed to awk.
If the var contains spaces, for the shell not to use the space as a separator, it should be u
This article mainly introduced the shell in the function return value exceeds the problem, the shell returns by return is limited, the maximum return 255, more than 255, then starts from 0 computation, needs the friend may refer to under
1. Preface
Almost six months did not write a blog, deserted for a long time, the work of the chores too much, their own more
The Linux shell can be user-defined functions and can be called casually in shell scripts. Here's how to define it, and what to call attention to. I. Defining shell functions (define function)Grammar:
[Function] funname [()]
{
Action
[Return int;]
}
Description
1, can be with function fun () definition, you can also directly
Label:Several cases of sqlplus and shell passing value to each other Scenario One: The simplest invocation of sqlplus in the shell $cat test.sh #!/bin/sh Sqlplus Oracle/[email Protected]>file.log SELECT * from Test; Exit EOF #注意EOF要顶格写 $sh test.sh $cat File.log --Omit a number of system prompt information------- Sql> EMPNO EmpName SAL DEPTNO -------------------
Several cases of sqlplus and shell passing value to each otherScenario One: The simplest invocation of sqlplus in the shell$cat test.sh#!/bin/shSqlplus Oracle/[email Protected]>file.log SELECT * from Test;ExitEOF #注意EOF要顶格写$sh test.sh$cat File.log--Omit a number of system prompt information-------Sql>EMPNO EmpName SAL DEPTNO-----------------------------10002 Fran
[Seemingly challenging] How does shell obtain the return value in php? for example, the php file returns an array nbsp; PHPcode lt ;? Phpreturnarray (a gt; 1, B gt; 2, c gt; public, d gt;, e gt ;,);? Gt; in she [seemingly challenging] How does shell get the return value in php?
The php file returns an array.
can use this method only if you want to split the results, such as with awk:Click ( here) to collapse or open
#!/bin/ksh
#
# created:2015.05.25
# updated:2015.05.25
# Author:jet Chenxi Zhang
# Description:get SELECT results in Shell
# Variable Definitions #
Oracle_sid=audtest
Oracle_home=/app/oracle/product/database/11.2.0/db_1
Path= $PATH: $ORACLE _home/bin
queryres=
Dbid=
Dbname=
Defining shell functions (define function)Grammar: [ function ] funname [()]{ action; [return int;]}说明:1. 可以带function fun() 定义,也可以直接fun() 定义,不带任何参数。2. 参数返回,可以显示加:return 返回,如果不加,将以最后一条命令运行结果,作为返回值。 return后跟数值n(0-255)。 Example (test_fun.sh): #!/bin/shfSum 3 2;fSum(){ echo $1,$2; return $(($1+$2));}fSum 5 7;total=$(fSum 3 2);echo $total,$?; From the above example we can get a few conclusions:
The function must be declared before the
* * #define Ex_config/* Configuration Error */#define EX__MAX//maximum listed value */ Use example one to exit the current shell[Email protected] ~]# [[email protected] ~]# exit logoutExample two in the script, go to the directory where the script is located, or exit the bash code
CD $ (dirname $0) | | Exit 1
CD $ (dirname $) | | Exit 1Example three in the script, determine the number of par
"Seemingly challenging" how the shell gets the value of return in PHP
Title PHP This file is to return an array
PHP Code
' 1 ', ' b ' = ' 2 ', ' c ' = ' public ', ' d ' = ' ', ' e ' = = ', '; >
In the shell how to receive this array ah or there is no way
------Solution--------------------
PHP Code
[User:root time:07:23:08 path:
#!/bin/shsum (){echo $ (($1+$2))return $ (($1-$2))}Sum $c=$ (sum $)echo $?Echo $cExecute command:./bashtest 1The operating result is:12--sum Results10--echo $? result because the value of return is ten12--echo $c result, the value is 12, so C will not be appended with the return value, echo $c call the Sum function, so print aour understanding of the return
In the process of writing shell scripts, we often customize some functions and execute the corresponding process according to the function's return value, so how do we get the return value of the function?There are two ways to call a function in the shell first:The first kind: valu
A problem was encountered today when writing a timed CP script, value too great for base (Error token is "08")The number system that originally started with 0 is recognized by default as an octal number, so my $datem-1 gets the month of the month in return: value too great for base (Error token is "08") This error, the solution isThe $datem format or the declaration is called decimal, ' 10# $datem '-1 so it
Tags: language adc its div mask execute i++ ret for loopImplementing a certain bit of a register with a shell scriptPit bit 1:Not recognized on the Development Board (Ubuntu can)For ((i=0;iDoDoneInto:For i in ' seq 0 6 'DoDonePit bit 2:return value by default only 8 bits are truncated.Setbits $ $4Regv=$?printf "regv=% #x \ n" $REGVFound only eight low-bits left.So, change the type of undertaking:regv= ' Re
Sync Post: http://blog.hacktons.cn/2017/12/13/shell-func-return/BackgroundWith Shell programming, custom functions are often required to write some tools for batch processing. In the case of more complex points, it may be necessary to return a value.Because in the shell world, unlike other programming languages, it does not support the methods we are familiar wit
How to assign the return value of a shell command to an application's variable.Bo Master recently made a router project, need to get the router now network status and parameters, using the UCI get GET,However, with system ("UCI get"), the obtained parameters are printed out directly in the terminal, which is not available in the application.The returned parameter. Here is my solution.#include #include #incl
Transferred from: Http://blog.163.com/[email protected]/blog/static/132229655201131055455754/Numeric operations:Only integer arithmetic is provided in bash, and the shell is implemented by the two commands of Let and expr .Use the format: let "x= $x +1" or x= ' expr $x +1 ' Also, in the shell, it is possible to pass ((an expression)). Use the format:((x= $x + 1))In the above three ways, the operator can a
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.