In the Linux system, you need to find some problems after assigning variables, you need to delete or replace the variable values. This article will give a detailed introduction to the replacement and deletion of Linux variable values. It is helpful to you.
1, the content to delete variable
[root @ bogon ~] # echo $ {PATH} # PATH variable value of the call
/usr /local /sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/mysql/bin:/root/bin
[root@bogon ~ ]# echo ${PATH#/*bin:} #See the ""#” symbol, indicating that the position from the left side of the variable "PATH" is deleted to the right and can be matched to the position of "*bin:”" The deletion can match the shortest one, so the output is as follows, “/usr/local/sbin:” is deleted
/usr/local/bin:/sbin:/bin:/usr/sbin :/usr/bin:/usr/local/mysql/bin:/root/bin
[root@bogon ~]# echo ${PATH#*local/bin:}
/Sbin:/bin:/usr/sbin:/usr/bin:/usr/local/mysql/bin:/root/bin
[root@bogon ~]# echo ${PATH##/*bin :} #两“#” indicates that the deletion can match the longest one, so “/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local /mysql/bin:”all deleted
/ro Ot/bin
[root@bogon ~]# echo ${PATH%:/*bin} #Change the above “#” number to “%” look, from the variable &ldquo The right side of the value of PATH” starts to delete to the left and can match the position of “*bin”, only the one that matches the shortest is deleted, so “:/root/bin” is deleted
/usr/Local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/mysql/bin
[root@bogon ~]# echo $ {PATH%%:/*bin} #两“%” Similar to the two “#”
/usr/local/sbin
2, variable content Replacement
[root@bogon ~]# echo ${PATH/sbin/SBIN/} #Replace “sbin” with “SBIN”, but only replace the first matching
/usr/local/SBIN/:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/mysql/bin:/root/bin
[root@bogon ~]# echo ${PATH//sbin/SBIN/} #Replace “sbin”, globally replace
/usr/local/SBIN/:/usr /lo Cal/bin:/SBIN/:/bin:/usr/SBIN/:/usr/bin:/usr/local/mysql/bin:/root/bin
Variable content deletion and replacement summary:
Variable writing mode function description
${variable name#matching character} If the variable content is matched, just delete it from the left side of the variable content, but delete the shortest matching
${variable name##matching character} If the variable content is matched, just delete it from the left side of the variable content, but delete the longest match, which can be understood as working in greedy mode
$ {variable name% match character} If the variable content is matched, just delete from the right side of the variable content, but delete the shortest matching
${variable name%% matching character} if the variable content is matched To, just delete from the right side of the variable content, but delete the longest match, can be understood as working in greedy mode at this time
${variable scale/old string/new string} from the variable content Matches on the left, replaces the old string with a new string, and replaces only the first matched string
${variable scale //String/new string} matches from the left side of the variable content, replaces the old string with the new string, and replaces the matched string with all
The above is the method for Linux to delete and replace variable values. This article only introduces the two methods of deleting and replacing, the modification of variables and the replacement methods, etc., will not be introduced here.
In the Linux system, the etc/profile file cant be changed. To change the etc/profile file, you need
Ubuntu 14.04 long-term support has come out, and many users cant wait to install it
Linux history command is used to view the used commands, often used in Linux system operations, is a
GOG is a foreign hot game sales website, we can buy and download popular games above, but GOG only h
Kali Linux crack wifi password with what software is good?
Ubuntu tips to start the deb installation package with the dpkg command
How to install OpenOffice on Linux system
Deep understanding of Linux text stream
Ubuntu 12.04 via XRDP Remote Desktop Method
What should I do if a Linux normal user does not have permission to use the command?
Krita software in the Linux system tutorial
How to install and set GlusterFS on CentOS 6.4
Linux system how to use the mount command and software to mount the ISO file
Linux system NBMA and BMA exchange method introduction
Linux installation third-party library error Python version 2.7 how to do?
Microsoft reiterates: Windows 10 upgrade is only free for Insider members
Win10 copying win95? Win95 vs Win10 change comparison chart
What is the process lsass.exe? Win7 boot prompts Lsass.exe system error how to do?
How to use soft links to solve directory transfer problems under Linux
Win7 how to set the password never expire?
Several ways to open the task manager under Win8 system (you don't know)
How to turn off the vocal reading in the background of win7
How to solve Win10 can not be activated properly? FAQ solution
WP8 version of WeChat does not support Didi taxis to grab red packets