Shell basic exercises & lt; 1 & gt;

Source: Internet
Author: User

1. the user is required to enter the name, age, and gender.

#! /Bin/bash

Read-p "Please input your name:" name

Read-p "Please input your age:" age

Read-p "Please input your sex:" sex

Echo "Your name is $ name, age is $ age, sex is $ sex ."

2. Write a script arvg. sh to read the input parameter variables, such as sh arvg. sh test12. Then, ask the user if they want to create a directory,

If the user answers yes or YES, it creates a directory for the user and then asks whether to create a file for the user. If yes is returned

Create test01 in the Created directory.

#! /Bin/bash

If [$ #-lt 1]; then

Echo "Please like 'sh test. sh a B C '"

Fi

Read-p "are you mkdir file? Please enter yes/YES or no: "qq

If [$ qq = yes] | [$ qq = YES]; then

Mkdir $1

For I in $ (seq 1 10 );

Do

Touch $1/test $ I

Done

Else echo "No file created"

Exit 0

Fi

3. Change the password randomly:

#! /Bin/bash

#2011/07/10 by larry

LOG = PassChange 'date + % F'. log

> $ Pass

Cat/etc/passwd | while read line

Do

Id = 'echo $ line | awk-F ":" '{print $3 }''

User = 'echo $ line | awk-F ":" '{print $1 }''

PASS = $ RANDOM

If [$ id-lt 500]; then

Echo "$ user is system users ."

Elif [$ id-gt 500]; then

Echo $ RANDOM | passwd $ user -- stdin

Echo "$ USER $ id $ RANDOM" >>$ LOG

Fi

Done

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

#! /Bin/bash

#2011/07/10

Now = 'date + % F'

File =/etc/passwd

For user1 in 'cat $ file | awk-F: '$3 <500 {print $1 }''

Do

Echo $ user1 is systerm user

Done

For user2 in 'cat $ file | awk-F: '$3> 500 {print $1 }''

Do

Echo $ RANDOM | passwd $ user2 -- stdin>/dev/null

Echo "$ user2 $ RANDOM"> Pass $ now. log

Done

This article is from the "Larry's learning path" blog

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.