Shell scripts ultrafast entry

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/bbvjx1314/article/details/102573612

Shell Programming

Summary:

Shell is a program written in C, you can access the operating system kernel services by Shell user.

Shell is both a command language is a programming language

The Linux Shell interpreter many species, there may be a plurality of system shell, can / shells command to view the system installed by the shell interpreter cat / etc.

Since Bash free and easy to use, widely used in daily work. Meanwhile, Bash is the default most Linux systems Shell.

Shell naming variables?

Variable name must be a letter or an underscore character "_" at the beginning, followed by letters, numbers, or the underscore character. Do not use a?, *, Or other special characters to name your variables

Shell interpreter

java virtual machine interpreter needs, empathy shell script also needs parser

  • [root@node04 shells]# cat /etc/shells
  • /bin/sh
  • /bin/bash
  • /sbin/nologin
  • /bin/dash
  • /bin/tcsh
  • /bin/csh
  • Shell special characters used to process parameters What does it mean ?

    • $ 0 Current file name of the script
    • $ N arguments passed to the script or function. n is a number that represents the number of parameters. For example, the first parameter is $ 1, $ 2 is the second parameter.
    • $ # Number of arguments passed to the script or function.
    • $ * All parameters passed to the script or function.
    • $ @ All the parameters passed to the script or function. When the double quotes ( "") contains, and $ * is slightly different, the following will be mentioned.
    • $? Exit status of the previous command, or the return value of the function. In general, most of the command is successful returns 0, failure to return 1.
  • Shell $$ current process ID. For Shell scripts, these scripts are located is the process ID

A writing shell scripts

① New /export/hello.sh file

#!/bin/bash

echo 'hello shell'                 

Solution:! # Convention is a tag that tells the system what the script requires an interpreter to perform that which Shell use.

  echo command for outputting the text window. 

Two shell scripts to perform a variety of ways

[root@node04 shells]# /bin/sh 01.sh
hello shell

[root@node04 shells]# /bin/bash 01.sh
hello shell

[root@node04 shells]#  ./hello.sh

hello shell

 

 

Guess you like

Origin blog.csdn.net/bbvjx1314/article/details/102573612