Shell script loop for while until and package management "on"
Loop execution
To run a code segment repeatedly multiple times
How many times to run repeatedly:
Number of cycles known beforehand
Number of cycles unknown beforehand
There are entry conditions and exit conditions
For, while, until
For variable name in list;
Loop body
Done
Execution mechanism: Assigns the element in the list to the "variable name" in turn; The loop body is executed once each assignment; Until the elements in the list are exhausted, the loop ends
List Generation Method:
(1) Give the list directly
(2) List of integers: (a) {start. End} (b) $ (SEQ [start [step]] end)
(3) command to return a list
(4) using glob, such as: *.sh
(5) variable reference; [email protected], $*
While loop
While CONDITION; Do
Loop body
Done
CONDITION: cyclic control conditions; Before entering the cycle, make a judgment; once each loop is judged again; the condition is "true", then a loop is executed until the condition test state is "false" to terminate the loop
Therefore: Condtion generally should have a cyclic control variable, and the value of this variable will be continuously corrected in the loop body
Entry condition: condition is true;
Exit Condition: Condition is false
until circulation until CONDITION; Do
Loop body
Done
Entry condition: CONDITION is False
Exit Condition: CONDITION is True
Continue and break of loop control statement
Loop Control statement Continue
Used in the loop body
Continue [n]: End of the nth layer of the current cycle, and directly into the next round of judgment; the inner layer is the 1th floor.
While CONDTIITON1; Do
CMD1
...
if CONDITION2; Then
Continue
Fi
Cmdn
...
Done
Loop control Statement Break
Used in the loop body
Break [n]: Early end of the nth layer cycle, the inner layer is the 1th layer
While CONDTIITON1; Do
CMD1
...
if CONDITION2; Then
Break
Fi CMDN
...
Done
Create an infinite loop
While true; Do
Loop body
Done
until false; Do
Loop body
Done
Unzip the archived tar
tar [OPTION] ...
(1) Create an archive
Tar-c-f/path/to/somefile.tar FILE ...
Tar Cf/path/to/somefile.tar FILE ...
(2) View the list of files in the archive file
Tar-t-f/path/to/somefile.tar
(3) Expand archive
Tar-x-f/path/to/somefile.tar tar-x-f/path/to/somefile.tar-c/path/
Combined with compression tool implementation: Archive and Compress-j:bzip2,-z:gzip,-J:XZ
Cpio copying from or to a file
The Cpio command is a redirected way of packaging a file for backup, restoring a recovery tool that can decompress files ending with ". Cpio" or ". Tar".
cpio [Options] > file name or device name
Cpio [Options] < file name or device name
Options
-o Package a file copy into a file or export the file to the device
-I unpack, unzip the package file or restore the backup on the device to the system
-T Preview, view the contents of the file or output to the file on the device
-V Displays the file name during the packaging process.
-D Unpack the directory, and automatically build the directory when Cpio restore
-C A newer storage method
For example
To back up the ETC directory:
Find./etc-print |cpio-ov >etc.cpio
Content Preview
Cpio–tv < Etc.cpio
To unpack a file
Cpio–iv <etc.cpio
Cpio–idv < Etc.cpio
Software operating Environment
Api:application Programming Interface
Posix:portable OS
Program Source--preprocessing----compile-to-link
Static compilation:
Shared compilation:. So
Abi:application Binary Interface
Windows is incompatible with Linux
ELF (Executable and linkable Format)
PE (Portable executable)
Library-level virtualization:
Linux:wine
Windows:cywin
Package Manager
Components of a binary application:
binary files, library files, configuration files, Help files
Package Manager:
Debian:deb file, dpkg Package Manager
redhat:rpm file, RPM Package Manager
Rpm:redhat Package Manager
RPM Package Manager
Package naming
RPM Package Naming method:
name-version-release.arch.rpm
VERSION:
Major.
Minor.
Release
Release:release. OS
Common arch:x86:i386, i486, i586, i686 x86_64:x64, x86_64, AMD64
Powerpc:ppc
Platform agnostic: Noarch
Package Naming and tools
Package: Sorting and unpacking application-version-arch.rpm:
Main package application-devel-version-arch.rpm
Development sub-Package application-utils-version-arhc.rpm
Other sub-packages application-libs-version-arhc.rpm
Other sub-packages
Between packages: There may be dependencies, or even cyclic dependencies
To resolve the dependency package management tool:
YUM:RPM Package Manager Front-end tools
Apt-get:deb Package Manager Front End Tool
RPM front-end management tools on Zypper:suse
Dnf:fedora + RPM Package Manager front-end management tool
Library files
To view the library files that the binaries depend on:
Ldd/path/to/binary_file
Manage and view the library files that are loaded natively:
Ldconfig
/sbin/ldconfig-p: Displays all available library files that have been cached by this computer
Name and file path mapping relationship
Configuration files:/etc/ld.so.conf,/etc/ld.so.conf.d/*.conf
Cache files:/etc/ld.so.cache
Package Manager
Package Manager: Features: Package files are packaged in one or several package files for easy and quick implementation of package installation, uninstallation, query, upgrade, and checksum management operations
1. package file composition (unique for each package)
The files in the RPM package
RPM metadata, such as name, version, dependency, description, etc.
Scripts to run when installing or uninstalling
2. Database (public)
Package Name and version
Dependent relationships
Function description
File path and checksum information generated after package installation
How to manage Packages:
Using Package Manager:
Rpm
Using the front-end tool:
Yum, DNF
RPM Package Management
Using the RPM command management package on the CentOS system:
Installation, uninstallation, upgrade, query, checksum, database maintenance
Installation:
RPM {-i|--install} [install-options] package_file ...
-v:verbose
-VV:
-H: Show package Management execution progress with #
RPM-IVH Package_file ...
RPM package installation [Install-options]
--test: Test installation, but do not actually perform installation; dry run mode
--nodeps: Ignoring dependencies
--replacepkgs | Replacefiles
--nosignature: Does not check the legitimacy of the source
--nodigest: Package integrity is not checked
--noscipts: Do not execute Package script fragment
%pre: Pre-installation;--nopre
%post: Post-installation script;--nopost
%preun: Unloading the forefoot;--nopreun
%postun: Post-uninstall script;--nopostun
RPM Package Upgrade
Upgrade:
RPM {-u|--upgrade} [install-options] package_file ...
RPM {-f|--freshen} [install-options] package_file ...
Upgrade: Install an older version of the package, then "Upgrade" if there is no legacy package, the "install"
Freshen: Install an older version of the package, "upgrade" if there is no legacy package, do not perform the upgrade operation
RPM-UVH Package_file ...
RPM-FVH Package_file ...
--oldpackage: Downgrade
--force: Forced escalation
Upgrade considerations
(1) Do not upgrade the kernel, Linux supports multi-core version coexistence, therefore, the direct installation of the new version of the kernel
(2) If the original package configuration file has been modified after installation, the new version of the upgrade
The same profile provided does not directly overwrite the old version of the configuration file, and the new version of the file is renamed (filename.rpmnew) after the retention
1. The sum of all positive integers within 100
#!/bin/bash
Read-p "First Number:" A
Read-p "second number:" B
[$a-ge $b] && echo "sum is" seq-s+ $b $a | BC ' "| | echo "Sum is" seq-s+ $a $b | BC ' "
[Email protected] bin]# bash shushu.sh
First Name is A:2
Second name is b:100
sum= 5049
2, through the ping command to detect the 172.16.250.1-254 range of all the host's online status, statistics online host and the number of offline host.
#!/bin/bash
Read-p "Please input a IPv4:" IP
Up=0 down=0
Ipv4= ' echo $ip |cut-d.-f1-3 '
For IPV in {0..255};d o
ip= "$IPV 4". " $IPV "
Ping "$IP"-C 1-w 1 &>/dev/null && echo "The Up IPv4 are: $IP" && let up+=1 &>/dev/null | | Let Down+=1 &>/dev/null
Done
echo "IPv4 ($IPV 4.1-255) up is: $up"
echo "IPv4 ($IPV 4.1-255) down is: $down"
3. Print 99 multiplication table
For i in {1..9};d o
For j in $ (seq 1 $i);d o
Echo-ne "${j}x${i}=$[i*j]\t"
Done
Echo
Done
Computer Demo
[Email protected] bin]# vim 999.sh
[Email protected] bin]# bash 999.sh
1x1=1
1x2=22x2=4
1x3=32x3=63x3=9
1x4=42x4=83x4=124x4=16
1x5=52x5=103x5=154x5=205x5=25
1x6=62x6=123x6=184x6=245x6=306x6=36
1x7=7 2x7=14 3x7=21 4x7=28 5x7=35 6x7=42 7x7=49
1x8=8 2x8=16 3x8=24 4x8=32 5x8=40 6x8=48 7x8=56 8x8=64
1x9=92x9=183x9=274x9=365x9=456x9=547x9=638x9=72 9x9=81
4. Generate 10 random numbers using variable random, output this 10 number, and show the largest and smallest of them
#!/bin/bash
Declare-i max=0
Declare-i min=0
For i in {1..10};d o
tmp= $RANDOM
[$i-eq 1] && min= $tmp
If [$i-le 9]; then
Echo-n "$tmp"
Else
echo "$tmp"
Fi
If [$tmp-gt $max]; then
max= $tmp
elif [$tmp-lt $min]; then
min= $tmp
Fi
Done
echo "The Max Random is $max"
echo "The min Random is $min"
5. Print Chess board
1#!
2 #
3 for I in $ (SEQ 1 8);d O
4 for J in $ (SEQ 1 8);d O
5 [$[i%2-$j%2]-eq 0] && echo-ne "\033[41m \033[0m" | | Echo-ne "\033[47 m \033[0m"
6 Let J + +
7 Done
8 echo ""
9 Let i++
Ten done
11
Shell script loop for while until and package management "on"