当前位置:网站首页>Conditional judgment of Shell Foundation
Conditional judgment of Shell Foundation
2022-07-24 21:32:00 【Test_ the_ rookie】
One 、 The role of conditional judgment
1. Tell the program which code block should be executed
2. The judgment statement can be executed separately
3. Judge by $? The returned results ,0 Said right , Not 0 Indicates an error (!!! Note that with conventional Boolean types 0、1 The difference between , The two are just the opposite .)
Two 、 The type of judgment
1. Arithmetic judgment : Use (()) Can complete arithmetic judgment ; To really return to 0, Returns... If false 1

2. String judgment
2.1 Determine whether a string is empty , Need to use -z、-n Parameters . among -n Indicates that the string is not empty , Return to true ;-z Indicates that true is returned when the string is empty .

2.2 Determine whether two strings are the same :[ character string 1 = character string 2 ] Note the string and []、= Space between

2.3 Determine whether there are multiple identical characters in the string :[[ “ character string ” == The character you want to match * ]]

2.4 Determine whether there is only one character in the string :[[ character string == The character you want to match ?? ]]

3. logic :&&( All conditions need to be met )、||( Any condition is satisfied )

4. Internal keyword comparison
4.1. -d flie==> Determine whether it is a directory , Usage for [ -d file name ];echo $?
4.2. -f file ==> Determine if it is a file
4.3 . -e file ==> Judge whether the file exists
4.4 . -r file: Determine whether the file is readable
4.5. -w file: Judge whether the document is writable
4.6 -x file : Determine if the file is executable
5. Command return code :
because shell After executing the order , There will be a return code , All can pass the return code $? Judge .
3、 ... and 、[] ,(()) And [[]] The difference between : It is recommended to use [[]]
1. All three can be used for conditional judgment
2.[[]] Support for wildcards , There is no need to escape
3.[] Escape must be used
4.(()) It can only be used for numerical comparison
------------------------ No end for learning
边栏推荐
- ma.glasnost.orika. MappingException:No converter registered for conversion from Date to LocalDateTime
- Acwing 94. recursive implementation of permutation enumeration
- Scientific computing toolkit SciPy image processing
- Alibaba cloud and parallel cloud launched the cloud XR platform to support the rapid landing of immersive experience applications
- [verification of ID number]
- CAD calls mobile command (COM interface)
- 驱动子系统开发
- Drive subsystem development
- A very useful log4net logging library
- [summary of Feature Engineering] explain what features are and the steps of feature engineering
猜你喜欢

Smarter! Airiot accelerates the upgrading of energy conservation and emission reduction in the coal industry

Dtable launched in the public beta, which is not only a table, but also a business application builder

Redis (12) -- redis server

Sword finger offer 15. number of 1 in binary

Use of cache in C #

whistle ERR_ CERT_ AUTHORITY_ INVALID

ma.glasnost.orika. MappingException:No converter registered for conversion from Date to LocalDateTime

About the acid of MySQL, there are thirty rounds of skirmishes with mvcc and interviewers

Baidu interview question - judge whether a positive integer is to the power of K of 2
![[basic data mining technology] KNN simple clustering](/img/df/f4a3d9b8a636ea968c98d705547be7.png)
[basic data mining technology] KNN simple clustering
随机推荐
CAD disable a button on the toolbar (WEB version)
Brand new: the latest ranking of programming languages in July
Class notes (4) (3) -573. Lecture hall arrangement (Hall)
IO flow overview
Defects of matrix initialization
APR learning failure problem location and troubleshooting
Strong reference, weak reference, soft reference, virtual reference
HSPF (hydraulic simulation program FORTRAN) model
C synchronous asynchronous callback state machine async await demo
[advanced data mining technology] Introduction to advanced data mining technology
250 million, Banan District perception system data collection, background analysis, Xueliang engineering network and operation and maintenance service project: Chinatelecom won the bid
Five digital transformation strategies of B2B Enterprises
Summary of communication with customers
[feature selection] several methods of feature selection
ECCV 2022 open source | target segmentation for 10000 frames of video
Go language error handling
731. My schedule II (segment tree or scoring array)
Scientific computing toolkit SciPy data interpolation
Unity & facegood audio2face drives face blendshape with audio
Baidu interview question - judge whether a positive integer is to the power of K of 2