Iv. shell input, output function and character color settings

Source: Internet
Author: User
Tags echo command

One, shell input function

1. Keyboard input Way One:
[Email protected] four]#CatTest.SH#!/bin/Bash #-the e parameter resolves the escape character in the statementEcho-E"My name is user1\n my name is User2"#-n parameter allows the echo command to end without wrappingEcho-N"My name is user1\n my name is User2"Echo#输出一个空行 # An application exampleEcho-N"Please enter your name:"Read nameEcho$nameEcho "My name is $name"[email protected] four]#./test.SHMy name is user1my name was user2my name is user1\n My name is user2 Please enter your name: TomTom 
Way two:
Cat Demo. SH #!/bin/' Enter your name:'  nameecho  $name [[Email Protected] four]#. /demo. SH Enter your name: TomTom
second, shell output function
[Email protected] four]#CatOutput.SH#!/bin/BashEcho "Hello world!"Echo-E"Hello world\nvery good!"Echo-E"\033[32;47m [test]\033[0m"

[email protected] four]#./output.SHHelloWorld!Helloworldverygood![Test]
3. Subtitle Color Change(1), Example:  
Cat Out2. SH #!/bin/echo""sh out2. SH httpd Process [OK]
(2), color syntax:\033[foreground background color m \033[0m #0m代表恢复到系统默认的颜色 (3), character interface foreground color and background color:Foreground: 30 Black 31 Red 32 green 33 yellow 34 Blue 35 violet 36 Cyan 37 White
Background color: 40 Black 41 red 42 green 43 yellow 44 cyan 45 Blue 46 Cyan 47 White 4. Other Commands(1), CatUsage: cat [options] ...    [File] ...       Output the [file] or standard input combination to the standard output. -B,--number-nonblank to the non-null output line number-E,--show-ends displays "$"-N at the end of each line,--number all line numbers of the output- S,--squeeze-blank does not output multiple lines of empty line-T,--show-tabs will be shown as the ^i use: the production menu, as follows: Example:
[Email protected] four]#CatA.SH#!/bin/BashCat<<x #注意: Can be any value, not X, indicating the end from X to X, output as-is input your name: #heredoc字符串1) User12) User23) User3x[[email protected] four]#SHA.SHPlease input your name:1) User12) User23) User3
(2), TeeUsage: tee [options] ... [File] ... Copies the standard input to each specified file and displays it to standard output. (Output one copy and save one copy)-A,--append content appended to the given file instead of overwrite-I,--ignore-interrupts ignores interrupt signal Example: good for edge output side saving
sh A.shtee  menu.txtplease Input your name:1) user12 ) user23lsA. SH demo. sh menu.txt out2. sh output. sh test. SH
(3), MorePagination View (4), HeadUsage: head [options] ... [File] ... Each of the specified files is The first 10 lines showto standard output. -C, which displays the contents of the first K bytes of each file;-N, which displays the first K-line contents of each file; (5), TailUsage: tail [options] ... [File] ... Displays the maximum of each specified file after 10 linesto standard output.  -C, Output the last K-byte; In addition, use the-C +k output-F from the K-byte of each file, and instantly output the data appended to the file changes. -N, outputs the last few lines (6), NL 添加行号
[Email protected] four]#CatB.SH#!/bin/BashCat/etc/passwd|Head-2|NLNL/etc/passwd|Head-2[email protected] four]#SHB.SH1ROOT:X:0:0: root:/root:/bin/Bash2BIN:X:1:1: bin:/bin:/sbin/Nologin1ROOT:X:0:0: root:/root:/bin/Bash2BIN:X:1:1: Bin:/bin:/sbin/nologin

Four, shell input, output function, and character color settings

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.