#!/bin/bash. Hellofunset"now going to thefuction Hello" hello# here will output the message:. /"back from thefunction Hello"6.6. function return Status valueExample 1:#!/bin/bashfunction Hello () { "Hello, today is ' date '" return 0 now going to thefunction Hellohello# next to output the return status value, with $? represents echo $? "back from thefunction Hello"Example 2: #!/bin/bashfunction Hello () {echo hello, today is ' date ' "
Tags: cut exit Express Concise tutorial Call Shell variable experience syntax table
Series article starter platform for Jelly want personal blog. Jelly think, is an original technical article sharing site. Here jelly will share his technical experience, technical gains and losses, technical life. I want to wait for you in jelly, and I hope you can share with me your technical loss and expectations.
find the command. /test. sh tells the system to find it in the current directory.Run the bash script in this way. The first line must be correct so that the system can find the correct interpreter.Here, the "System" is actually the shell application (IMAGINE Windows Explorer), But I deliberately write it as a system for ease of understanding. Since this system refers to
find the correct interpreter.The "system" here is actually the shell application (imagine Windows Explorer), but I deliberately write the system, is easy to understand, since this system refers to the shell, then a script using/bin/sh as an interpreter can save the first line? Yes.As an interpreter parameterThis works by running the interpreter directly, whose parameters are the file names of the
This article is part (iv) of the Linux Shell Series tutorial, more on the Shell Tutorial: Linux Shell Series Tutorials
Like many programming languages, there are annotation symbols in the shell, and today we introduce the synta
. Shell scripts are the process IDs of these scripts.
The parameter passed to the script when the command line parameter is run is called the command line parameter. The command line parameters are represented by $ n. For example, $1 indicates the first parameter, $2 indicates the second parameter, and so on.
See the following script:
Copy text-only new window
#! /Bin/bash
Echo "File Name: $0"
E
Shell TutorialsThe shell is a program written in C that is a bridge for users to use Linux. The shell is both a command language and a programming language.A Shell is an application that provides an interface through which users access the service of the operating system kernel.Ken Thompson's SH is the first UNIX
Shell Getting Started Tutorial: Shell variables
Variable
A variable is a place to store data temporarily, and is a memory space. Bash shell and other programming languages, there is no "data form", which means that the default is not to distinguish between a variable is an
Create a script
There are many different shells in Linux, but usually we use Bash (Bourne again shell) for Shell programming because bash is free and easy to use. So the script I've provided in this article is all about using bash (but in most cases these scripts can also be
Create a scriptThere are a lot of different shells in Linux, but we usually use bash (Bourne again shell) for Shell programming because bash is free and easy to use. So the script I've provided in this article is all about using bash (but in most cases these scripts can also
3.Shell Input and output3.1.echoThe echo command can display a line of text or a variable, or output a string to a fileecho [option] string-E: Parsing escape characters-N: Carriage return is not newline, Linux system default carriage return lineEscape character: \c,\f,\t,\n ...Example Program #!/bin/bash#echoecho -e " this Echo ' s 3 new lines\n\n\n echo ok " echoecho " this Echo ' s 3 new lines \n
First, topsy variables and environment variables
Variables are an essential part of any programming language and are used to hold variables of various types. Scripting languages are mostly weakly typed languages (dynamic languages), which means that when you use a variable, you don't have to declare the type of the variable in advance, just assign the value directly. In bash, the value of each variable is
, you'll find that using a shell to prototype your application is also useful in the development step.
Shell variables
Defining variablesWhen you define a variable, the variable name is not a dollar sign ($), such as:
Variablename= "Value"
Note that there can be no space between the variable name and the equals sign, which may be different from any programming language you know. At the same time, the na
resultThis is the name of the script:./parm.sh This is the first positional parameter of the script: a two: B Three: C Four: D five: E 6:7: 8:9:Role 2: Pass parameters to system commands, such as#!/bin/bash#parm_1.shfind/home/perfect/shell-name $1-printExecutes the command chmod u+x parm_1.sh, and then executes the./parm_1.sh myfile.txt, which is equivalent to the command find/home/perfect/
1. Connect MySQL database The way to connect to a database in a shell is simply to specify a username, password, the name of the database to connect to, and then redirect to enter the MySQL statement as follows: Mysql-u username-p PASSWORD DATABASENAME show databases;Eof But this is not a good idea, any user using the script can see the database user's account and password, to solve this problem, you can use a MySQL database special configuration file
Shell supports custom variables. When defining a variable, the variable name does not contain a dollar sign ($), for example:
Copy text-only new window
Variablename = "value"
variableName="value"Note that there is no space between the variable name and equal sign, which may be different from all programming languages you are familiar. Variable names must follow the following rules:
The first character must be a letter (a-Z, A-Z ).
There cannot b
of parameter 1 is greater than or equal to parameter 2
Example:#!/bin/bashdeclare i lenlen=$1if [$len-eq 100]; Thenecho ' length of ' elseecho ' length is not 100, but $len "fiRow 4, the command-line positional parameter, gets the value of Len's variable.4. Conditional Judgment on bash options
Serial Number
Judging Type
under what circumstances is true
1
-O SET option name
If this option i
Linux Shell script series tutorial (2): terminal printing command details
This article mainly introduces the Linux Shell script series (2): terminal printing command details, this article focuses on echo terminal printing, printf terminal printing two Print Output commands, for more information, see
Terminal Printing
A terminal is an interactive tool that allows
have to worry about the effects of some bash special characters on the operator, do not write a bunch of escape characters, such as [[Str In addition to [[]], in bash, there is no need to ignore the effects of the special characters mentioned above.Below, there is another point to pay special attention to:In [[judging]] , if you use = = or! =, and the string to the right of the two operators does not add s
Linux Shell script series tutorial (7): script debugging
This article mainly introduces the Linux Shell script series (7): script debugging. This article describes the Bash built-in debugging and custom debugging functions. For more information, see
I. debug the script
Debugging is one of the important features that ev
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.