Linux Shell Script Raiders (1.1)

Source: Internet
Author: User

1.1 Introduction
  • The design of many Unix-like operating systems is breathtaking. Even today, decades later, UNIX-style operating system architectures are still one of the best designs ever. One of the most important features of this architecture is the command-line interface or shell. The shell environment enables users to interact with the core functions of the operating system. The term script is more about this environment. Scripting usually uses some kind of interpreter -based programming language. Shell scripts are essentially text files , and we can write a series of commands that need to be executed, and then execute them through the shell.

  • Here we introduce the Bash shell (Bourne Again Shell), which is currently the default shell environment for most gun/linux systems. All the experiments in the book were done in the Ubuntu14.04 LTS environment.

    Basic operations
  • Open Terminal
    In the ubuntu14.04 LTS system, a terminal has been installed by default, and we can open the terminal in a number of ways. Here are two types of:
    method One: through the system comes with the retrieval system, we can easily find the terminal (Terminal), click to open. The retrieval system can be started by a button in the upper right corner of the Quick Launch bar.
    method Two: in order to easily open the terminal after, it is recommended that the terminal fixed in the Quick Launch bar. How to do this: After you open the terminal through the method, the Quick Launch bar will appear a terminal chart, right-click on the chart, select "pinned to the start bar" to pin the terminal in the Quick Launch bar.

  • Terminal Initialization Interface
    By default, the terminal prompt is:[Email protected] orwhoRooT@hosTName#. Represents a normal user, #代表root用户.
    For example: After I open the terminal, the prompt is: [email protected]:~$.
    Root is the most privileged user in a Linux system, and the ability to do so is a big risk, so don't mind using the root user as the default user of the login system.

  • Switch Users
    Typically, for a personal Linux operating system, there are two users on the system, the user itself and the root user. For the consumer, there is a need to switch users to perform actions that ordinary users cannot perform, and there are two ways to switch users here.
    method One: temporarily switch. As the name implies, this switching method is only temporary, when the instruction execution is completed, it will switch to the original user. The Toggle command is:sudo command, sudo is a shorthand for super user do.
    method Two: long-term switching. As the name implies, after switching with this method, the instruction execution will not return to the normal user after completion. The Switch command is:su, Su is the shorthand of switch user, then prompts for password and so on to complete the user switch.

  • Shell Script
    The following script is used to print Hello world! to the terminal String.

#!/bin/bashecho"Hello World!"

The starting line of the shell script is usually #!/bin/bash, where/bin/bash is the path to the interpreter to interpret the subsequent commands. Each command is separated by a line break or semicolon.

    • Run the script
      In Ubuntu, there are many ways to run scripts.
      method One: bash test.sh, in which case the first line of the script file does not have to be "#!/bin/bash" because the interpreter has been specified in this way.
      method Two: first modify the script file permissions chmod a+x test.sh, this instruction is to give the script file executable permissions. Then execute the file./test.sh, or you can execute the script through the full path.

    • Script Comments
      In shell scripts, it is no exception, we need to provide comment lines in some places, like code that is easy to understand. #后面的内容为注释内容, will not be interpreted to perform. Note:#是单行注释符.

Reference
    • Linux Shell Script Raiders (2nd edition)

Linux Shell Script Raiders (1.1)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.