Home  >  Article  >  Java  >  [shell programming] syntax

[shell programming] syntax

巴扎黑
巴扎黑Original
2017-06-26 11:20:101067browse

1. Declare variables

myUrl="http://see.xidian.edu.cn/cpp/linux/"
myNum=100

Note:
There cannot be a space between the variable name and the equal sign, which may be different from all programming languages ​​you are familiar with.
At the same time, the naming of variable names must follow the following rules:
The first character must be a letter (a-z, A-Z).
There can be no spaces in the middle, and underscores (_) can be used.
Punctuation marks cannot be used.
You cannot use keywords in bash (you can use the help command to view reserved keywords).

2. Use variables

echo ${your_name}
Note: It is recommended to add curly braces to all variables. This is a good programming habit.

3. Redefine variables

myUrl="http://see.xidian.edu.cn/cpp/linux/"
echo ${myUrl}
myUrl= "http://see.xidian.edu.cn/cpp/shell/"
echo ${myUrl}

Note: You cannot write $myUrl="http:// during the second assignment. see.xidian.edu.cn/cpp/shell/", only add the dollar sign ($) when using variables.

4. Read-only variables

myUrl="http://see.xidian.edu.cn/cpp/shell/"
readonly myUrl
myUrl="http: //see.xidian.edu.cn/cpp/danpianji/"

Run the script, the results are as follows:
/bin/sh: NAME: This variable is read only.

五, Delete variables
After a variable is deleted, it cannot be used again; the unset command cannot delete read-only variables.
unset variable_name

6. Variable type
When running the shell, there will be three types of variables:
1) Local variables
Local variables are defined in scripts or commands, and are only defined in scripts or commands. Valid in the current shell instance, programs started by other shells cannot access local variables.
2) Environment variables
All programs, including programs started by the shell, can access environment variables. Some programs require environment variables to ensure their normal operation. Shell scripts can also define environment variables when necessary.
3) Shell variables
Shell variables are special variables set by the shell program. Some of the shell variables are environment variables and some are local variables. These variables ensure the normal operation of the shell

The above is the detailed content of [shell programming] syntax. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn