Linux Beginner Bash related

Source: Internet
Author: User
Tags lowercase

Bash's color display rules:

ASCLL Encoding for color settings


\033:ctrl Key

[: Control the spacing character between character and color code

0m: command to turn off color properties

1m: Bold for displayed text characters

4m: Multibyte underline "\033[4mhellow word\033[0m" for text word

5m: Make text characters blink

7m: Exchange The background color of text characters with foreground color display

8m: Set the background and foreground colors of text characters to a color


30m-39m: Sets the foreground color of text characters; 38m and 39m are not available


40m-49m: Sets the background color of the text character; 48,49m temporarily useless.


Example: Echo-e "\033[4;5;33;43mhellow word\033[0m"

A complete program should include four types of files:

Binary header and library file help document profiles


One of the BASH--CLI (Command line interface)

Bash also belongs to the full application, with these four types of files:

Bash configuration file:

Three categories:

Profile class:

Configuration file that implements the function initialization for the interactive logon shell process

BASHRC class

A configuration file that implements the feature startup configuration for a non-interactive logon shell process

Logout class:

A configuration file that provides the ability to terminate and clean the class for the interactive logon shell process


Shell type:

Shell for Interactive logon:

Shell process opened after entering the account password directly from a terminal

Use Su-username su-l username to perform a toggle login open shell Process

Non-interactive logon shell:

In the graphical interface, the shell process of the terminal opened via the menu or right-click menu

Using SU username to perform a switch login open shell process


Bash configuration file:

Profile class:

Global: Profiles that are in effect for all users:

/etc/profile

/etc/profile.d/*.sh


Note: In the Red Hat series of operating systems, usually, a configuration file a lot of content, the format is complex, we will cut it into multiple fragments, the cut out of the pieces of the unified in the "program name. D" directory, in such a directory is saved in the folder files, most will be in a unified file

Prefix name to name

User profile: A profile that is valid only for a user;

~/.bash_profile


The role of profile profiles:

1. Define the user's environment variables

2. Run a script or execute a command


BASHRC class:

Global:

/etc/bashrc

User Personal

~/.bashrc


The role of the BASHRC class configuration file:

1. Defining Local Variables

2. Defining Command Aliases

3. Define Umask


Note: Only the root user can modify the global class configuration file, and users can only modify the personal profile in the home directory



The following configuration files are loaded sequentially by the interactive logon shell process:

/etc/profile/etc/profile.d/*.sh ~/.bash_profile ~/.BASHRC

/etc/bashrc


For non-interactive logon shell processes, the following configuration files are loaded in order:

~/.bashrc/etc/bashrc/etc/profile.d/*.sh


All command operations executed at the command line, as long as the file modification is not involved, is generally valid only for the current shell life cycle, as long as the shell process is finished, the desired setting fails


The role of the configuration file: The configuration information that we rely on to survive can be long-term, as long as the content in the configuration file is not modified, every time you open

The shell will make the previous configuration take effect


How to make the newly defined configuration in the configuration file effective immediately:

1.sourse command:

Sourse/path/to/some_conf_file

. /path/to/some_conf_file

2.exec command

Exec/path/to/some_conf_file


How the string is handled in the variables stored in bash:

Weak variables:

can be used without prior definition

No hard requirements for variable data type, default is character type


1. String slices:

${#var}; Returns the length of the variable var of the string type

${var:offset} returns the content after the offset character in the string variable var, excluding the offset value range of offset [0-string length-1]

${var:offset:number}: Returns the string Blvar starting after the first offset character and the length of number characters

${var:-length}: Takes the rightmost length of the entire string


2. Take a substring based on the pattern:

${VAR#*PATTRN}: From left to find the string stored in the var variable, the first pattern-matched character, removing all strings from the beginning of the string to the first character of the pattern match

${VAR##*PATTRN}: From the left and then to find the string stored in the var variable, all characters that are pattern matched, delete all strings from the beginning of the string to the last character of the pattern match

${var%pattrn*}: From right to left to find the string stored in the var variable, the first pattern-matched character, removing all strings from the end of the string to the first character of the pattern match

${var%%pattrn*}: From right to left to find the string stored in the var variable, the first pattern-matched character, removing all strings from the end of the string to the last character of the pattern match


3. Find Replacements

${yar/pattern/substring}: Find the contents of the match PATTERN in the Var variable. Replace the result of its first match with substring

${yar//pattern/substring}: Find the contents of the match PATTERN in the Var variable. Change all of its matching results to substring


${var/#PATTERN/substring}: Find the content in the VAR variable that matches the PATTERN at the beginning of the line. Replace the matching results with substring

${var/%pattern/substring}: Find the content of the line end matching PATTERN in the VAR variable. Replace the matching results with substring


4. Find and delete

${yar/pattern}: Find the contents of the match PATTERN in the Var variable. Delete the result of its first match

${yar//pattern}: Find the contents of the match PATTERN in the Var variable. Delete all of its matching results

${yar/#PATTERN}: Find the contents of the match PATTERN in the Var variable. Delete the result of a line match

${yar/%pattern}: Find the contents of the match PATTERN in the Var variable. Delete the result of a line ending match


5. Case conversion of characters

${var^^}: Converts all lowercase letters in the VAR variable to uppercase letters

${var,}: Converts all uppercase letters in the VAR variable to lowercase letters


6. Assigning Values to variables

${var:-value}: If the variable var is empty or not set, then return the value of value directly otherwise the value of Var

${var:+value}: Returns value if variable var is not empty

${var:=value}: If the variable var is empty or not set, return the value of value directly and assign value to Var; otherwise, return the value of Var directly


7. Indirect references to variables

If the value of the first variable is exactly the variable name of the second variable, the method that refers to the value of the second variable from the first variable is called the indirect variable reference

Var1=var2

Var2=value

Bash provides two ways to refer to indirect variables in a format

Eval myvar=\$ $var 1

myvar=$ (!var1s)


Linux Beginner Bash related

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.