Ubuntu command learning: delete, replace, and replace variable content in bash

Source: Internet
Author: User

Ubuntu command Learning: the deletion, substitution, and replacement of variable content in bash may often be replaced. For example, if I installed a software, however, the executable file of the software is not updated to the environment variable. Therefore, you have to go to the bin directory of the Installation File every time and execute the corresponding executable program to start the program, this is a very troublesome thing. You can append the bin directory to the path environment variable so that the application can be started in any PATH. However, for cainiao who have just started using Ubuntu, everything is not so smooth. You may make mistakes or even make a mistake in the PATH environment variable. This is really a fatal error, how to deal with the variable content becomes a key. The one-step method is as follows: Enter the executable program folder, and then run the command [cpp] PATH = $ PATH: $ (pwd) or PATH = $ PATH: 'pwd'/* Note that 'here is not a single quotation mark, but the symbol in the upper left corner of the keyboard, which is next to 1 */, so it must be foolproof. But for cainiao, you are likely to write it like this: [cpp] PATH = $ PATH :$ {pwd}/*, that is, your parentheses become braces, and $ () this is the mode of the first command. The wrong command will write */or [cpp] PATH = $ PATH: 'pwd'. The output of the two processing methods is: [cpp]/usr/lib/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin: /bin:/usr/games:/usr/lib/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin: /usr/bin:/sbin:/bin:/usr/games: pwd at this time, you must use the deletion and replacement rules of the variable content to modify the rules, as shown in the following table: variable setting method description $ {Variable # keyword} If the data starting with the header matches the "keyword", the shortest data that matches the keyword is deleted $ {Variable ## keyword}. If the variable content starts with the "keyword ", the longest matching data will be deleted $ {Variable % keyword}. If the variable content is forward from the end of the data with the "keyword ", delete the matching shortest data $ {Variable % keyword}. If the variable content is forward from the end ", delete the longest matching data $ {Variable/old string/new string}. If the variable content conforms to the "Old string ", replace $ {Variable // old string/new string} with the new string. If the variable content matches the old string ", the new string is used to replace the old string. Therefore, if you want to restore the preceding variables to a prototype, perform the following operations: For [cpp]/usr/lib/lightdm: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games: Apply operation: [cpp] PATH =$ {PATH % :} For [cpp]/usr/lib/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin: /sbin:/bin:/usr/games: pwd apply operation: [cpp] PATH =$ {PATH %: pwd, the above is a simple process of variable processing, and there is a small point to note, such as this operation: [cpp] echo PATH =$ {PATH #/* lightdm :} although the result displayed on the terminal does remove the first PATH in the PATH variable, but the value of the PATH variable has not changed, you can try echo $ PATH again. In fact, the PATH is still the original value. To make the corresponding operation take effect for the variable, you must assign a value. That is, let [cpp] PATH =$ {PATH # lightdm :}

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.