Get the App
SLTechnology News&Howtos  ›  Servers  › 

Analysis of DAY2 shell exercises

Shulou Source: shulou.com Published: 2022-06-01 03:11:09 11月01日 Update

In this issue, the editor will bring you an analysis of DAY2 shell exercises. The article is rich in content and analyzed and described from a professional point of view. I hope you can get something after reading this article.

Exercise 1

Write a shell script to copy all the directories under the / app/oracle/utils directory (only one level is needed) to the new directory.

#! / usr/bin/bash

Cd / app/oracle/utils

For f in `ls`; do

If [- d $f], then

Cp-r $f / tmp

Fi

Done

Summary of error points:

1 spaces before and after brackets

There is no parameter r after 2 cp. If there are files under the directory, it will indicate that it cannot be pasted.

# # omiting directory

Exercise 2

Write shell script, batch build user user_00, user_01,... User_100 and all users belong to the users group

$cat user_day2.sh

#! / bin/bash

Groupadd users

For i in `seq-f "user_g" 0100`; do

Useradd-g users $I

Done

If you don't know how to use seq-f, you can use the following:

#! / bin/bash

Groupadd users

For i in `seq 0 9`; do

Useradd-g users user_0 $I

Done

For j in `seq 10 100`; do

Useradd-g users user_$j

Done

The above is the analysis of the DAY2 shell exercises shared by the editor. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Tags: Analysis directory content user script professional small and medium rich content parameters that is copy file article more knowledge space article industry perspective information Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB MySQL OPPO Reno vpn Shulou Technology