In the first line of the executable, we usually specify what interpreter to use to execute the file, such as the shell script, the beginning of the file is usually #! /bin/sh
Running the shell will encounter three variables
1. Local variables, defined in scripts or commands, are valid only in the current shell instance, and other shell-initiated programs cannot access local variables.
2. Environment variables, so the program, including shell-initiated programs, can be used to ask environment variables, some programs require environment variables to ensure their normal operation, when necessary, shell scripts can also define environment variables.
3.shell variables are special variables that have shell program settings, part of the shell variables are environment variables, and some are local variables, which ensure the normal operation of the shell.
When defining a variable, the variable name must begin with "A-za-z" , with no spaces or punctuation (can be used with "_", underscore), variable name can not use bash keyword, call variable, only need to precede the variable name with ' $ ' can be called, In view of the problem of the interpreter recognizing the boundary, we usually have a variable name outside the parentheses to determine the variable name.
Deleting a variable can use unset to cancel the definition of the variable.
#代表注释
Now we create a demo file and give it permission to enter the following inside:
After you finish editing the demo.sh script
Give the script a execute permission chmod +x demo.sh
Once you give the script a permission to execute it, you can execute it:/demo.sh can do it.
You can see the results of the execution. Variables have been replaced.
At the end of the script I deleted the variable myName, and I output the variable myName because the variable has been deleted, does not exist, so there is a blank line at the end of the demo.sh script execution;
Shell syntax-shell defining variables and calling variables