Shell Programming Details (iii)

Source: Internet
Author: User
Tags case statement

String test:

= =: Test for equality, equality is true, not equal to False

! =: Tests are not equal, unequal to true, equal to False

>

<

-N String: Tests whether the specified string is empty, empty is true, not empty is false

-S string: Tests whether the specified string is not empty, is not empty, and empty is false


BC Command usage

For example: echo "SCALE=2;111/22;" | BC reserved two-bit accuracy


Loop control

For

While

Until


for variable in list; Do

Loop body

Done


Generating a list of integers

1. {1..100}

2, ' SEQ [number of start] [step] End number

For example: SEQ 1 2 10 generates cardinality from 1 to 10


Script instance: Generate 10 random numbers and find the maximum and minimum values

#!/usr/bin/ksh

Declare-i max=0

Declare-i min=0

For num in {1..10}

Do

Myrandom= $RANDOM

If [$num-eq 1]; Then

min= $myRandom

Fi

If [$num-lt 10]

Then

Echo-n "$myRandom,"

Else

echo "$myRandom"

Fi

[[$myRandom-gt $max]] && max= $myRandom

[[$myRandom-lt $min]] && min= $myRandom

Done

echo "Max= $max"

echo "Min= $min"


Case statement:

Case variable in

value1)

statement;;

Values

statement;;

*)

statement;;

Esac


This article is from the "Forget the Past" blog, please be sure to keep this source http://xujingbo.blog.51cto.com/4633099/1828219

Shell Programming Details (iii)

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.