Unix shell learning notes

Source: Internet
Author: User
Tags file copy

Recently I reviewed some Unix shell programming. In fact, UNIX is a very good operating system, and it may not be as easy as Windows XP in terms of ease of use and user experience. However, many underlying ideas and script technologies are constantly evolving, including many excellent ideas, algorithms, and design strategies, which are also worth learning. Although you do not need to use shell programming at work for the time being, and do not want to let the previous accumulation fade away, I still feel that I should leave some experiences.

Some shell definitions are excerpted: the main interface for text and operating system external is shell.


Shell is the outermost layer of the operating system. Shell manages the interaction between you and the operating system: Wait for your input, explain your input to the operating system, and process the output results of various operating systems. Shell provides communication between you and the operating system. This communication can be executed in interactive mode (input from the keyboard and get a response immediately) or in shell script (non-interactive) mode. Shell scripts are a string of Shell and operating system commands stored in files. They can be reused. Essentially, shell script is a simple combination of command line commands into a file.


When reviewing Unix shell programming, there were two key points: 1. UNIX Cron file configuration, it provides a matching expression for the date format, allowing the operating system to run some tasks according to the format-defined schedule ), this reminds me of the quartz integrated by spring and the very precise and powerful crontrigger expression. You can configure complicated schedule for the program to notify the application to execute a job. 2. the tee command redirects the output stream to the standard output and another file copy or pipeline. I think the obvious reference for this stream redirection idea is log4j, in essence, it is a redirection of the log output stream, and provides powerful matching filtering rules, which can be used to format the data in the stream. Other study notes --

  • The essence of the kill command is to send a signal to a process. It is called kill only to terminate the process.
  • Redirection> and>. The former is the overwrite mode, and the latter is the append filling mode.
  • The difference between variable replacement and reference is that replacement is the process of parsing metacharacters, and reference is to cancel replacement of some metacharacters.
  • Environment variables must be export before they take effect for all child processes.
  • Shell differentiates quotes: single quotes indicate that a string of characters are taken one by one, double quotes indicate that variable replacement is allowed, and reverse quotes indicate that commands can be executed and the commands in quotation marks are replaced as output results.
  • Before creating a new process, the process will call the fork command to clone itself.
  • When a process is cloned, the original process is called the parent process. The pdid attribute stores the PID of the parent process.
  • Links are not a unique type of files. The file system allows more than one directory item to point to a specific file.

When I first studied shell, three concepts were very confusing: grep, awk, and sed. I checked some materials and thought about them:

1. grep, global search Regular Expression and print out. It searches for string templates in one or more files. If the template contains spaces, it must be referenced. All strings after the template are considered as file names. The original content is not affected when the search results are sent to the screen. It may be a widely used match search method.

2. awk is an excellent text processing tool and a powerful data engine. The names are from three founders: Alfred Aho, Peter Weinberger, and brain kernihan. It is a style scanning and processing language that allows simple creation of short programs, reading input files, and performing calculations for data sorting, processing data, and generating reports. It increases the processing capability compared to only matching grep. Of course, the speed will decrease and the resource consumption will increase.

3. Sed is a non-interactive context editor that edits large files or requires multiple global functions to scan the input data. It edits a file or a copy of the standard input. The standard input may come from the keyboard, redirection, variable, or another pipeline.

 

For the operating system, at the machine language level, most of the calculations executed by the CPU are processed by filtering, calling, running, and managing some text (text) in the memory, compared with the advanced programming languages Java and C ++, these scripting languages have more powerful text processing capabilities and concise syntax. I don't know if I have any chance to study Unix shell or use it at work in the future. Anyway and shell are really excellent technologies and are never outdated at all!


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.