Linux shell programming-advanced usage of Variables

Source: Internet
Author: User

Linux shell programming ---- advanced usage of variables 1 Internal Variable 1 internal variables refer to variables that can affect the behavior of bash shell scripts. They are effective for shell and its subshells. 2 below we will introduce several common internal variable name meanings BASH bash records the bash shell path, usually/bin/BASH, we can use echo $ BASH to view the host name HOSTNAME record the host name HOSTTYPE record the hardware architecture of the system MACHTYPE is also record the hardware architecture of the system OSTYPE record the type of the Operating System 2 string processing 1 next we will introduce the expr command, it is mainly used to process string 2 to calculate the string length $ {# string} Or expr length $ string 3 expr index Command expr index $ string $ substring // The function is to match on string position where substring appears for the first time, if no value is returned for the 0 4 expr match command expr match $ string $ substring // The function matches the substring at the beginning of the string and returns the matched length, if the start character does not match, 0 is returned. The substring can be a string or a substring extracted from string by regular expression 5 # {string: position} // extract substring from position to end # {string: position: length} // extract length-long substring 6 from position to delete substring $ {string: subdtring} // Delete the shortest substring that matches the substring at the beginning of string $ {string: # substring} // Delete the nth child string that matches the substring at the beginning of the string, and replace the 7th child string $ {string/substring/resplacement} // only replace the child that matches the substring for the first time. string $ {string // substring/resplacement} // replace all child matching the substring

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: 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.