Learn more about the character test of Linux and the practice of bash scripting

Source: Internet
Author: User

Learn more about the character test of Linux and the practice of bash scripting



One, character test options

= =: Tests whether two strings are equal, equals true, and not equal to false.

! =: Tests whether two strings are unequal, unequal to true, and equal to false.

-N String: Tests whether the specified string is empty, NULL is true, and is not NULL for false.

-Z String: Tests whether the specified string is not empty, is not empty, is true, and Null is false.


Second, complete the following bash scripting exercises

Exercise: Write a script

Pass a parameter (single-character on line) to the script, such as Q, Q, quit, or quit, to exit the script, otherwise, the user's parameters are displayed;


#!/bin/bash

#

if [$ = ' Q '];then

echo "Quiting ..."

Exit 1

elif [$ = ' Q '];then

echo "Quiting ..."

Exit 2

elif [$ = ' Quit '];then

echo "Quiting ..."

Exit 3

elif [$ = ' Quit '];then

echo "Quiting ..."

Exit 4

Else

echo $

Fi


Write a script:

Determine the current host CPU manufacturer whose information is in the Vendor ID row in the/proc/cpuinfo file.

If its manufacturer is AUTHENTICAMD, it will be shown as AMD;

If its manufacturer is Genuineintel, it will be displayed as Intel Corporation;

Otherwise, it is said that it is a non-mainstream company;


650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/43/AD/wKiom1Pbtt6R7DUgAACoC1g0soY233.jpg "title=" 36020140801234201757.jpg "alt=" Wkiom1pbtt6r7dugaacoc1g0soy233.jpg "/>


650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/43/AD/wKioL1Pbt9_xNVKDAAAg3jAbCUg703.jpg "title=" 36020140801234222299.jpg "alt=" Wkiol1pbt9_xnvkdaaag3jabcug703.jpg "/>



Practice:

Pass three parameters to the script, the first is an integer, the second is an arithmetic operator, the third is an integer, the result of the calculation is displayed, and the two-bit precision is required to be preserved. Shaped like:

./calc.sh 5/2


#! /bin/bash

echo "scale=2; $1$2$3 "| Bc





This article is from the "lost the year of the Sao" blog, please be sure to keep this source http://8855546.blog.51cto.com/8845546/1533997

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.