Break exit loop continue advance into the next round of the cycle while special usage

Source: Internet
Author: User

write a script that has the instinct to create multiple yum sources in the same repo file. definition of the Yum repository in the last lesson

1, accept a file name as a parameter, this file is stored in the/ETC/YUM.REPOS.D directory, and the filename. Repo is the suffix; request that the file cannot exist beforehand, otherwise error;

2, in the script, remind the user to enter the repo ID, if quit, exit the script, otherwise continue to complete the steps;

3, repo name and BaseURL path, and then in the format of repo file to save it to the specified file;

4, the enabled default is 1, and Gpgcheck default is set to 0

5. This script is executed several times, unless the user specifies the repo ID as quit

Review:., [email protected]/etc/yum.repos.d/[email protected][email protected] from the current line to the last line replace this for the

#!/bin/bash

#

Repofile=/etc/yum.repos.d/$1

If [-e $REPOFILE]; Then

echo "is exist."

Exit 3

Fi

Read-p "Repository ID:" Repoid

until [$REPOID = = ' quit ']; Do

echo "[$REPOID]" >> $REPOFILE

Read-p "Repository name" Reponame

echo "Name= $REPONAME" >> $REPOFILE

Read-p "Repository Baseurl" Repourl

echo "Baseurl= $REPOURL" >> $REPOFILE

Echo-e ' enabled=1\ngpgcheck=0 ' >> $REPOFILE

Read-p "Repository ID:" Repoid

Done

########################################################################################

Calculate up to 100 of all odd and continue advance into the next round of cycle

#!/bin/bash

#

Let sum=0

Let I=0

While [$I-LT 100]; Do

Let i++

If [$[$I%2]-eq 0]; Then

Continue

Fi

Let sum+= $I

Done

Echo $SUM

#################################################################################### #3

calculate the sum>5000 of all positive integers within 1000 and do not add when the Break Early exit loop - e file exists

#!/bin/bash

#

Declare-i sum=0

For I in {1..100}; Do

Let sum+= $I

If [$SUM-GT 5000]; Then

Break

Fi

Done

Echo $I

Echo $SUM

##################################################

Format:

while read line; Do

Done </path/to/somefile

Judge the user under/etc/passwd which user's shell is under the bin bash, if it is bash display this user's user name, otherwise not displayed;

and 6 messages are automatically exited, and the user ID is less than or equal to 505 is not displayed

#!/bin/bash

#

Let I =0

file=/etc/passwd

while read FILE; Do

[' Echo $FILE | awk-f: ' {print $} '-LT 505] && continue

[' Echo $FILE | awk-f: ' {print $7} ' = = '/bin/bash '] && echo $FILE | Awk-f: ' {print '} ' && let i++

[$I-eq 6] && break

Done < $FILE

############################################################################################################### ####

1. Determine if a specified bash script has a syntax error, and if there is an error, remind the user to type Q or Q to ignore the error and exit, and any other key can be vim to open the specified script

2, if the user through Vim open Edit and save exit, there are still errors, repeat the first step of the content, or the normal shutdown exit

#!/bin/nbash

#

Bash-n $

Until Bash-n $ &>/dev/null; Do

Read-p "Some error q/q to quit others for edit" CHOICE

Case $I in

q| Q)

echo "Something Wrong"

Exit 5;;

*)

Vim + $;

Esac

Done












Break exit loop continue advance into the next round of the cycle while special usage

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.