Read,for,case,while,if Simple Example

Source: Internet
Author: User

Read is used to remove each line from a file for processing

Cat read. SH #!/bin/bashecho"using read"cat name.txt |  while Read name  Do Echo " name is $name "  Done

For multiple to remove a file from a stack of files for processing

$Cat  for.SH#!/bin/BashEcho "using for"I=0 for file inch*. txt DoEcho "file name is $file"I=`Expr$i +1` DoneEcho "we have $i files"

The case is used to process the shell script with different parameters after it

$Cat  Case.SH#!/bin/BashEcho "using case" Case$1 inch-a)Echo "You are using-a";;-b)Echo "You are using-b";;*)Echo "You input was not correct, and please input-a or-b";;Esac

If more is used for various condition judgments, such as size, file existence etc.

$Cat if.SH#!/bin/BashEcho "using If"if[-F $1 ] ThenEcho "$ a regular file"elif[-D $1 ] ThenEcho "is a directory"fi

Note: Represents a parameter followed by a script

Read,for,case,while,if Simple Example

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.