linux shell programming foundation

Create a shell script

1. Use a text editor to create a text file

  • The first line shell declaration must include the sequence:! #
    Example:! # / Bin / bash
  • Add Comments: Comments begin with #

2. Run the script

  • Give execute permissions, specified on the command line script absolute or relative path
  • Directly run the interpreter, the script interpreter program as an argument

Script Specification

  1. The first line calls for the use of language in general
  2. Program name, to avoid changing the file name can not find the right file
  3. version number
  4. Time after the change
  5. Author Information
  6. The role of the program, and precautions
  7. Finally, a brief description of each version of the update

The basic structure of the script ▷

#!SHEBANG
CONFIGURATION_VARIABLES
FUNCTION_DEFINITIONS
MAIN_CODE

  shell script example

#!/bin/bash
# ------------------------------------------
# Filename: hello.sh
# Revision: 1.1
# Date: 2019/05/26
# Author: GUO
# Email: [email protected]
# Website: www.magedu.com
# Description: This is the first script
# Copyright: 2017 wang
# License: GPL
# ------------------------------------------
echo “hello world”
  •   Script Debugging

Syntax error detection script

bash -n /path/to/some_script

Debug executive

bash -x /path/to/some_script

 

Guess you like

Origin www.cnblogs.com/guopeilin/p/10926759.html