Understand basic shell scripts

Overall format: ①, the first line of she (#) bang (!) Mechanism #! / Bin / bash #! / Usr / bin / python

                  ②. Comment (writable or not). Configure .vimrc in advance under ~ /. Canonical suffix: .sh

                  ③, add execution authority to the script

                  ④, run the script

Method of running script: ①, absolute path

                         ②, relative path

                         ③ Put into the $ PATH variable such as: mkdir / data / script mv hello.sh / data / script echo "PATH = / data / scripts: $ PATH" >> / etc / profile.d / ldy.sh

                         ④, bash script name (test)

                         ⑤, cat script name | bash (not under the host, network download)

For example: build a website on other host a: service http start. This website special folder: / var / www / html, put the script hello.sh in it

       On this host b: curl http: // a's ip / hello.sh, check if there is a virus or rm -rf, make sure to put it into the pipeline | bash to execute. (curl instead of browser webpage)

Debugging: bash -n can only judge syntax errors

           bash -x tracing to find wrong statements

Variable: built-in

          Custom (no need to indicate the type, floating point numbers are not supported)

Scope: ordinary variables (only for the current shell, subshells are not supported)

           Environment variables (support zishell. Bash command to create subshell directly)

           Local variables (functions)

set view all variables

unset cancel variable

Guess you like

Origin www.cnblogs.com/ldyaly/p/12747292.html