A simple shell tutorial

Source: Internet
Author: User
Tags echo command php programming

Shell Tutorials
The shell is a program written in C that is a bridge for users to use Linux. The shell is both a command language and a programming language.
A Shell is an application that provides an interface through which users access the service of the operating system kernel.
Ken Thompson's SH is the first UNIX shell,windows Explorer to be a typical graphical interface Shell.
Shell Online Tool
Shell Script
Shell script, a scripting program written for the shell.
The shell is often referred to by the industry as a shell script, but reader friends know that Shell and shell script are two different concepts.
For reasons of habit and brevity, the "shell programming" appearing in this article refers to Shell scripting, not the development of the shell itself.
Shell Environment
Shell programming is like Java and PHP programming, as long as there is a text editor that can write code and a script interpreter that can explain execution.
There are many types of shell in Linux, common:
Bourne Shell (/usr/bin/sh or/bin/sh)
Bourne Again Shell (/bin/bash)
C Shell (/USR/BIN/CSH)
K Shell (/usr/bin/ksh)
Shell for Root (/sbin/sh)
......
This tutorial focuses on bash, the Bourne Again Shell, which is widely used in daily work due to its ease of use and free. At the same time, bash is the default shell for most Linux systems.
In general, people do not differentiate between the Bourne shell and the Bourne Again shell, so, like #!/bin/sh, it can also be changed to #!/bin/bash.
#! tells the system that the program specified after the path is the shell that interprets this script file.
First shell script
Open a text editor (you can use the Vi/vim command to create a file), a new file test.sh, the extension sh (sh for Shell), the extension does not affect the execution of the script, see the name is good, if you write Shell script in PHP, the extension is good for PHP.
Enter some code, the first line is usually this:
Instance
#!/bin/bash
echo "Hello world!"

"#!" is a contract tag that tells the system what interpreter the script needs to execute, even if it uses a shell.
The echo command is used to output text to a window.
There are two ways to run a shell script:
1. As an executable program
Save the above code as test.sh and CD to the appropriate directory:
chmod +x./test.sh #使脚本具有执行权限
./test.sh #执行脚本
Note, be sure to write./test.sh, not test.sh, run other binary programs as well, direct write Test.sh,linux system will go to the path to find there is no test.sh, and only/bin,/sbin,/USR/BIN,/USR /sbin wait in path, your current directory is usually not in path, so write test.sh will not find the command, to use./test.sh tells the system that it is looking in the current directory.
2. As an interpreter parameter
This works by running the interpreter directly, whose parameters are the file names of the shell scripts, such as:
/bin/sh test.sh
/bin/php test.php
The script that runs this way does not need to specify the interpreter information in the first line, and it is useless to write.

A simple shell tutorial

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.