Shell Programming for Loop

Source: Internet
Author: User

1. Grammatical structure

2. Case studies

2.1 Batch Decompression

#!/bin/bashcd/root/test/ls *.tar.gz > Ls.logls *.tgz >> ls.logfor i in $ (cat ls.log)        do                tar-zxf $i &A mp;>/dev/null        donerm-rf ls.log~                                                                           ~                                                                           ~                                                                                                                                                   "for2.sh" 11L, 145C

2.2 Adding a specified number of users in bulk

#!/bin/bashread-p "Input username:"-t-nameread-p "input Total No. of users: "-t-numread-p" Input password for users: "-t-pswif [! -Z "$name"-A! -Z "$num"-A!                -Z "$PSW"] then y=$ (echo $num | sed ' s/[0-9]//g ') if [-Z ' $y] Then For ((i=1;i<= $num; i=i+1)) Do/usr/sbin/useradd $name $ I &>/dev/null echo $pass |                                                                                  /USR/BIN/PASSWD--stdin $name $i &>/dev/null done fifi~                                                                                  ~                                                                                                                                                                 ~ "For4.sh" 19L, 422C 

2.3 Delete all regular users in bulk

#!/bin/bashusr=$ (cat/etc/passwd | grep/bin/bash | grep-v root | cut-d ":"-f1) for I in $usr        do                userdel-r $i 
   done~                                                                                  ~                                                                                  ~                                                                                                                                                                  "for5.sh" 9L, 127C

  

Shell Programming for Loop

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.