Getting Started with Shell programming-bash tutorials

Source: Internet
Author: User

Shell script is similar to batch processing under Windows/dos, that is, the use of various commands pre-placed into a file, convenient one-time execution of a program file, mainly for the convenience of administrator settings or management. However, it is more powerful than batch processing under Windows and is more efficient than editing programs with other programming programs, and it uses commands under Linux/unix.

In other words, shell script is a program written using the shell's function, which uses a plain text file, writes some shell syntax and instructions inside, and then uses formal notation, pipeline commands, and data flow redirection to achieve the purpose we want. More clearly, shell script is like the early Dos era. bat, the simplest function is to write a lot of instructions together, so that the user can easily execute multiple commands in one operation, and shell script provides an array, loop, condition and logical judgment and other important functions , allowing users to write programs directly to the shell without having to use the syntax written by traditional programs like the C programming language.

There are many different shells in Linux, but usually we use Bash (Bourne again shell) for Shell programming because bash is free and easy to use. A shell script file starts with #!/bin/bash, and the comment begins with #.

Here are a few ways to execute shell scripts at the terminal: (Need to add executable permissions chmod +x filename)

1. Switch to the directory where the shell script is located and execute:

[Email protected] ~]#./hello.sh

2. Execute as an absolute path:

[Email protected] ~]#/root/desktop/hello.sh

3. Execute directly with bash or SH:

[[email protected] ~]# Bash hello.sh 4. Execute [[email protected] ~]# in the current shell. hello.sh or [email protected] ~]# source hello.sh When writing shell scripts, note that the program must start with #!/bin/sh (must be in the first line of the file), the symbol #! used to tell the system it The following parameters are the programs that are used to execute the file. In this example we use/BIN/SH to execute the program (or #!/bin/bash).

Getting Started with Shell programming-bash tutorials

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.