In this tutorial, How to use Bash substitution string. I usually use bash substitution. Bash script the essential for DevOps Roles.
Bash substitution string
From the beginning #
Remove the first matching pattern from the beginning of the string
#!/bin/bash FILE="/usr/local/www/DevopsRoles.com/foo.txt" echo "Path File: $FILE" echo ${FILE#*.} echo ${FILE#*/} echo ${FILE#*m}
The screen output terminal:
Remove the last matching pattern from the beginning of the string
#!/bin/bash FILE="/usr/local/www/DevopsRoles.com/foo.txt" echo "Path File: $FILE" echo ${FILE##*.} echo ${FILE##*/} echo ${FILE##*m}
The screen output terminal:
From the end equal %
Remove the first matching pattern from the end of the string
#!/bin/bash FILE="/usr/local/www/DevopsRoles.com/foo.txt" echo "Path File: $FILE" echo ${FILE%.*} echo ${FILE%/*} echo ${FILE%m*}
The screen output terminal:
Remove the last matching pattern from the end of the string
#!/bin/bash FILE="/usr/local/www/DevopsRoles.com/foo.txt" echo "Path File: $FILE" echo ${FILE%%.*} echo ${FILE%%/*} echo ${FILE%%m*}
The screen output terminal:
Conclusion
Thought the article, you can use Bash substitution string as above. I hope will this your helpful. More details refer to Bash script.