1, editor, compiler, Run method (3 ways to execute the script)
(1) Shell program is text format, as long as the text editor can be. But because our shell is running under a Linux system, the line break must be ' \ n ' and the line break under Windows is "\ r \ n", so the editor-written shell in Windows cannot run under Linux. So our entire course was written and debugged under Linux using the VI editor (which is actually vim).
(2) The compiler is not involved, because the shell is an explanatory language and can be run directly after editing.
(3) There are several ways to run the shell program, here are three methods:
The first type:./xx.sh, as in running binary executable methods. Running the shell this way requires the shell program to have executable permissions. chmod a+x xx.sh to add executable permissions.
The second: source Xx.sh,source is a command of Linux, and this command is used to execute a scripted program. This operation does not require the script to have executable permissions.
The third type: Bash Xx.sh,bash is a script interpreter, essentially an executable program. This execution is equivalent to executing a bash program and then passing xx.sh as argv[1] to him.
2. Hello World Procedure and explanation
(1) The first line of the shell program is generally: #!/bin/sh this jargon begins with #!, followed by a pathname, which means to specify which interpreter is interpreted by the shell program when it executes. So here we write/bin/sh meaning that this shell will be executed by the SH executable in the/bin directory of the current machine.
You can write the first line as: #!/bin/bash to specify that the script be executed using bash.
Note: The interpreter sh, which is used by default on Ubuntu, is not actually bash, but dash. Dash is the scripting interpreter used by default in Ubuntu.
(2) The comments in the script use #, #开头的行是注释行. If you have more than one line to comment on, precede each line with #. (#就相当于是C语言中的//)
(3) The body of the shell program is composed of many line shell statements.
3. The shell is not mysterious
(1) The shell is the program that executes the command typed in the previous command line. The shell is actually a technique that is invented to avoid repeated manual input at the command line, to record manual input steps, and then to re-retell the manual input process of the original record by executing the shell script program.
(2) Shell editing can be run directly (do not need to compile)
(vi) write a first shell