Linux shell Programming Notes-shell input and output -2-read-cat-pipe _ block chain

Source: Internet
Author: User

1. Read command

The read command reads information through a keyboard or a line of text in a file and assigns a value to a variable.

1.1, read reading the keyboard data, the input of the content before the return of the data assigned to a variable:

cb@standalone14:~$ read name
Hello CB I am ubuntu.    #回车
cb@standalone14:~$ echo $name
Hello CB I am ubuntu.    #显示变量的值
1.2, instance shell script, save code as. sh file, change executable permissions, run See effect:

#!/bin/sh
# var test
Echo-n "The name: \c"
read name
echo-n "middle name: \c"
Read Middle
ech  O-n ' Last name: \c '
read surname

Echo ' the ' $name
Echo ' middle name is ' $middle
Echo ' last Name is "$surname

2, Cat command

The cat command is used to display the contents of a file and can display 1 or more files.

    The cat command is used to display the contents of a file and can display 1 or more files.
    Cat myfile    #显示myfile的文件内容, will display all content at once, to avoid when large files;
    cat myfile1 myfile2 > Myfile3    # Redirect the contents of Myfile1 and Myfile2 to Myfile3;
    Cat myfile | More #把myfile的内容传递给 command, with more commands to achieve pagination display;


3, Pipeline

Pipeline, which enables the output of one command to be passed to another command as its input.     The pipeline is represented by |. General form: Command 1 | Command 2 ls-l |     The output of the grep CB # ls command is piped to the grep command. In one line of commands, you can use multiple pipes, and the pipes will be executed from left to right.


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.