2016-08-16
Content of the lesson:
Shell Script Basics: Looping, for,while,until (not finished)
Package Management (not finished):
Software operating Environment
Package Basics
RPM Package Management
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
Loop Control statement:
Break :"lift end loop, loop will no longer execute" refers to the previous loop exit, and after exiting the command continues to execute, while exit exits the entire script
continue:"to end this cycle, and go to the next cycle" when the continue statement is encountered, the statement after the continue is no longer executed, directly ahead of the next round of circulation
For loop
For variable name in list;
Loop body
Done
List: Spaces separated by numbers, characters, files, and so on
Implementation 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
For example:
Write a script that prompts for the value of the positive integer n to calculate the sum of the 1+2+3+...N
#!/bin/bash #Version: 1.0 #Create time:2016-08-15 13:51:02 #Description: Write a script that prompts for the value of positive integer n, calculates the sum of 1+2+3+...N let sum=0 read-p "Input num:" num expr $NUM + 0 &>/dev/null [$? -ne 0] && echo "Please input Digitnum" && exit [$NUM-le 0] && echo ' Input the right NUM ' & amp;& Exit for I-in ' seq $NUM ' do sum=$ (($SUM + $I)) did echo "The sum is $SUM" unset SUM unset NUM
While loop:
While CONDITION; Do
Loop body
Done
Entry condition: condition is true;
Exit Condition: Condition is false
That is, when the loop body is really performing the loop body, the loop body is false is the exit loop body
For example:
Sum of all positive integers within 100
#!/bin/bash#version:1.0#create time:2016-08-15 14:36:00#description: Sum of all positive integers within 100 let sum=0let num=1while [$NUM-le Do sum=$ (($SUM + $NUM)) num=$ (($NUM + 1)) Doneecho "1+2+...+100= $SUM"
Until cycle
Until CONDITION; Do
Loop body
Done
Entry condition: CONDITION is False
Exit Condition: CONDITION is True
"That is, when the loop body is really the loop body, the loop body is false is to exit the loop body, in contrast to the while loop
Package Management:
Software operating Environment
Program Source--preprocessing----compile-to-link
Note content is removed during preprocessing
Abi:application Binary Interface
Windows is incompatible with Linux, such as the LS command no longer works with Windows because Uwindows and Linux have different ABI interfaces
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 files, RPM Package Manager, SuSE series also use RPM Package Manager
Rpm:redhatpackage Manager (initial)
RPM Package Manager(industry standard, similar to GNU)
Package naming
Source code: NAME-VERSION.TAR.GZ|BZ2|XZ
VERSION:major.minor.release
RPM Package Naming method:
name-version-release.arch.rpm
Example: bash-4.2.46-19.el7.x86_64.rpm
VERSION:major.minor.release (that is, how the source code is named)
Release:release. OS
OS:EL7, referring to the RHEL7 version.
Common arch:
X86:i386, i486, i586, i686 (32-bit platform)
X86_64:x64, x86_64, AMD64 (64-bit platform)
Powerpc:ppc
Platform agnostic: Noarch
Package: One RPM package contains multiple files
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
Since a binary executable package consists of binary files, library files, Help files, and configuration files, each package file includes:
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:
1. Installation
RPM {-i|--install} [install-options] package_file ...
-V: Show details
-H: Show Progress in #
[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
2. 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, then "Upgrade"
If the legacy package does not exist, the upgrade operation is not performed
RPM-UVH Package_file ...
RPM-FVH Package_file ...
--oldpackage: Downgrade
--force: Forced escalation
This article from the "6638225" blog, reproduced please contact the author!
Linux Basic Learning-11th day (script loop, package management)