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 and execute the corresponding file every time... 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 :}
Related Article

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.