Shell theory Study (iii)

Source: Internet
Author: User

37. Adjust the properties of a variable

    • Read-only variable: use the readonly command

      ReadOnly variable Name

    • ReadOnly Other uses

      • ReadOnly or readonly-p: Displays a list of variables that currently have read-only properties

      • readonly-f function Name: Set the function cannot be modified

      • READONLY-A array Variable: Set-a followed by the variable name is a read-only array

    • Read-only variable: using declare

      650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/59/6F/wKioL1TTCW3xIhENAAM0t-edeCE595.jpg "title=" 1.PNG " alt= "Wkiol1ttcw3xihenaam0t-edece595.jpg"/>


38. Custom Environment Variables

    • When you log on as a normal user

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/59/6F/wKioL1TTC0vAbG9vAADceDIwE4g923.jpg "title=" 3.PNG " alt= "Wkiol1ttc0vabg9vaadcediwe4g923.jpg"/>

    • When working in the role of the system administrator, there are three environment variable profiles

      • /etc/profile

      • /etc/bash.bashrc

      • All files under the/etc/skel directory

39.Here Document

Basic usage:

[[email protected] ~]# cat >>123.txt<< end> Hello > My name is ' Jack ' > Welcome to bj> Endyou has New mail In/var/spool/mail/root[[email protected] ~]# cat 123.txt Hello my name is "Jack" Welcome to BJ
    • Here document also supports variable substitution. In the input, if there is a variable, bash will replace the variable value before turning.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/59/6F/wKioL1TTE92yLp0NAACk8q-GaiE255.jpg "title=" 4.PNG " alt= "Wkiol1tte92ylp0naack8q-gaie255.jpg"/>

    • How to use in variables

[Email protected] ~]# wow= ' wow,great! ' [Email protected] ~]# m1=$ (cat <<HERE> Line 1 was good.> they are jack,marry and john.> $WoW > Here>) [Email protected] ~]# echo $m 1line 1 is good. They is Jack,marry and John.
    • How to close a variable

[Email protected] ~]# m1=$ (cat << "Here" > Line 1 is good.> they be jack,marry and john.> $WoW > here> ) [[email protected] ~]# echo $m 1line 1 is good. They is Jack,marry and John. $WoW
    • Multi-line annotations

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/59/73/wKiom1TTFjOwmdmpAADrNum83yA469.jpg "title=" 5.PNG " alt= "Wkiom1ttfjowmdmpaadrnum83ya469.jpg"/>

40. How to test if a variable exists

Syntax: ${variables to be tested-default value}

Explanation: To determine whether the variable being tested exists, if the variable exists, it returns the value of the variable, if not it will pass the default value to the variables to be tested

    • Determine if a variable exists

[[email protected] ~]# unset myname[[email protected] ~]# r=${myname-' basher '}[[email protected] ~]# echo $rbasher
[Email protected] ~]# myname= "Jack" [[email protected] ~]# r=${myname-' basher '}[[email protected] ~]# echo $rJack
    • Determine if the variable does not exist or is empty

[[email protected] ~]# myname=[[email protected] ~]# r=${myname:-' basher '}[[email protected] ~]# echo $rbasher [[Email Pro Tected] ~]# unset myname[[email protected] ~]# r=${myname:-' basher '}[[email protected] ~]# echo $rbasher
    • Use if to judge

      650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/59/73/wKiom1TTHCOCpQAYAABP65J52yw063.jpg "title=" 6.PNG " alt= "Wkiom1tthcocpqayaabp65j52yw063.jpg"/>

    • Test whether the variable "does not exist" or its value is empty: Prompt for error message

Syntax: ${variables to be tested:? Prompt message}

Explanation: Determine whether the variable "does not exist" or "empty", if the condition is true, then display: after the prompt message. and immediately stop executing the script

To disassemble an expression:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/59/74/wKiom1TTIDPiB-7bAAEcm389dZM027.jpg "title=" 7.PNG " alt= "Wkiom1ttidpib-7baaecm389dzm027.jpg"/>

Example:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/59/74/wKiom1TTIMjgt_e1AAEZHBPM6qQ329.jpg "title=" 8.PNG " alt= "Wkiom1ttimjgt_e1aaezhbpm6qq329.jpg"/>

This article is from the "Linux Revolution" blog, so be sure to keep this source http://kaibinyuan.blog.51cto.com/7304008/1612017

Shell theory Study (iii)

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.