Shell BASICS (1) starting from Hello World

Source: Internet
Author: User

Note: Here are the shell notes I made. Next, we will provide a series of notes.

Shell is a scripting language, so there must be an interpreter to execute these scripts. Common shell script interpreters in Unix/Linux include bash, sh, CSH, and KSh. They are used to being called a shell. We often talk about the number of shell types. In fact, it refers to the shell script interpreter.

As for the introduction and differences between these script interpreters, I am not clear about them. I should check the information myself. In fact, it is not very important to know whether or not I know it. This does not affect whether you can use shell.

1. Create a new file, such as lottu01.sh, with the extension SH (SH stands for shell). The extension does not affect script execution. Let's start with "Hello World.

#!/bin/bashecho "hello world !"

Note: "#!" Is an agreed tag, which tells the system what interpreter is required to execute this script, that is, which shell is used. Use bash.
Echo: Is the output command in shell, and outputs the string following it to the screen. -- This is also known to all.

2. Run the script

$ Chmod + x lottu01.sh # grant the script execution permission $./lottu01.shhello world!

Note that you must write it as./test. Sh instead of test. Sh.

Write test directly. sh, the Linux system will go to the path to find whether it is named test. sh, and only $ home/bin, $ home/sbin,/usr/bin,/usr/sbin and so on are in the path. Your current directory is usually not in the path, therefore, it is written as test. sh cannot find the command. /test. sh tells the system to find it in the current directory.
Of course, you can also write test. Sh. Perform the following operations:
CP lottu01.sh ../bin/# ../bin is under the bin of the home directory of the current user. Don't misunderstand this.
Then test whether lottu01.sh is OK.

$cp lottu01.sh ../bin/$ lottu01.sh hello world !

3. read command

ECHO is the output in shell, So input. Read. -- This will be explained in detail in later sections -- read.

#! /Bin/bash # Author: lottu # copyright (c) li0924 # Start scriptecho "Please input your name? "Read nameecho" Hi, $ {name} "test: $ chmod + x lottu02.sh $./lottu02.sh please input your name? Lottu -- name you entered here. Hi, lottu

[Note]

1. The first line of the script -#! /Bin/Bash; it is the interpreter of the script. Of course, you can leave it empty. At that time, you must execute it like this.
/Bin/bash script;
2. Echo, READ command; this will be added later.

Shell BASICS (1) starting from Hello World

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.