The linux shell script (a)

Tsuhaifu

Speaking at the command line easy way, there is something not fail to mention, is the wildcard.

"*" Any number can represent multiple characters, "?" Sign stands for any one character.

cp * .jpg ./aaa

daily_backup.sh
given "executable" file permissions.
chmod + x ./daily_backup.sh

Run the script
./daily_backup.sh

The script does not require a specific file extension, as long as the text file with executable permissions to.
Extension single general practice on the script file named .sh.

#! / bin / bash
to "#" at the beginning of a comment. However, the "#!" Put together also appears in the first line of the script, it is not annotate it.
This line is used to specify the meaning of Shell script needs.

Run the script
bash ./myscript.sh

Script execution time, it will skip the first function in the part written, until the implementation of a line to
call the function, and then come back to perform.

Shell variables in simple, casual. Do not have to declare, as used with writing, come in handy is a variable.
value = 128

When using variables you need to add "$" symbol in front of the variable to indicate that this is a variable.
#! / bin / the bash
value = 128
echo value
echo $ value

echo is a command for screen-printing characters. Can be written directly behind the string, you can also use variables.

The script does not give a clear statement variable type. This is because only one type of variable Shell, is the string. Not
what integer, float the concept of class.

expr specifically for Shell scripts, responsible for several string variable mathematical calculations.
#! / bin / the bash
NUM =. 8
NUM = 'NUM exprt $ +. 1'
echo $ NUM

Print Number 9

The so-called environmental variables, somewhat similar to the C language, global variables, which are valid throughout the system.
To make a variable to become global variables is very simple, as long as the assignment plus the export front in variable
#! / bin / the bash
Export. 8 env_num =
echo $ env_num

Environment variables expire after the end of the current session.

Guess you like

Origin blog.csdn.net/baiyibin0530/article/details/92843462