Shell script learning notes-Introduction and basic formats
Source: Internet
Author: User
Shell script learning notes-Introduction and basic format shell introduction shell the original English meaning is shell, shell meaning. In linux, the shell in unix is a command line interface that accepts user commands. When the shell executes the program, it will request the kernel to start a new process and execute the current sequence in the process... shell script learning notes-Introduction and basic format shell introduction shell the original English meaning is shell, shell meaning. In linux, the shell in unix is a command line interface that accepts user commands. When the shell executes the program, it requests the kernel to start a new process and execute the current sequence in the process. the specific implementation is that the shell calls the fork function to generate a new process, in the new process, call the exec function to load the specified program. Shell can execute binary executable files (elf files) or script files (with executable permissions ). For processing script files, shell starts a new shell. The basic format of shell scripts is because there are many shell implementations. the default shell used in linux is bash, but there are many other shells, such as B shell and c shell. Therefore, when writing shell scripts, we need a mechanism to inform the kernel about which shell we need to execute our scripts. The shell script uses the first line in the script to identify which shell to use. [Html] #! /Bin/bash all shell scripts start with one line above. Script #! At the beginning, the complete path of the interpreter is followed by parameters. the kernel will call the interpreter according to the corresponding parameters. We compile a simple script program nusers. sh, which shows the number of users currently logged on to the system. [Html] #! /Bin/bash who | wc-l who command prints information about the currently logged-on user, and transmits the result to the wc program for processing through pipelines, wc-l prints the number of lines output by the who command (the who command displays the information of each user in one row), that is, the number of users.
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.