Shell Scripting Exercise A

Source: Internet
Author: User

if Multi-branch statement practice

#!/bin/bash

read-p " Please enter 100 m running seconds: "I

If [$i-lt] && [$i-GT 0]

Then

echo " Enter the final "

read-p " enter male and female "a

if [$a = male]

Then

echo " into the men's group "

elif [$a = female]

Then

echo " Enter the women's group "

Else

echo "Error"

Fi

elif [$i-ge 10]; Then

echo " elimination "

Else

echo " Error "

Fi

Case Statement Practice, automatically unzip the compressed file according to the filename suffix

Vim untar.sh

#!/bin/bash

Case $ in

*.gz)

If [-F $]

Then

TAR-ZXVF $1-c/opt

Fi

;;

*.BZ2)

If [-F $]

Then

TAR-JXVF $1-c/opt

Fi

;;

*)

echo " file format Error "

Esac

For integers less than 100 and

#!/bin/bash

Sum=0

read-p " Enter an integer less than 100: "N

If [$n-lt 100]; Then

For I in $ (seq 1 $n)

Do

Let sum= $sum + $i

Done

echo " from 1 to $n, so the number of integers is $sum "

Else

echo " input Error "

Fi

Odd and, even, and equal to less than 100

#for Statement Format

#!/bin/bash

Sum=0

For i in {1..100..2}

Do

Let sum= $sum + $i

Done

echo " Cardinality and = $sum "

Sum=0

For I in $ (SEQ 0 2 100)

Do

Let sum= $SUM + $i

Done

echo " Even and = $SUM "

#while Statement Format

#!/bin/bash

A=1

B=0

While [$a-le 100]

Do

If [' Expr $a% 2 '-eq 1]; Then

# if [$ ($a%2)-eq 1]; Then

Let b= $b + $a

Fi

Let a++

Done

echo " Cardinality and = $b "

A=1

C=0

While [$A-le 100]

Do

# if [' Expr $A% 2 '-eq 0]; Then

If [$ ($A%2)-EQ 0]; Then

Let c= $c + $A

Fi

Let a++

Done

echo " Even and = $c "


Shell Scripting Exercise A

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.