bash manipulating string

FileName="/var/www/html/index.html"
echo "${FileName}"
/var/www/html/index.html
 
echo "${FileName%/*}"
/var/www/html
 
echo "${FileName##*/}"
index.html
 
TmpVal=$(echo "${FileName%.*}")
echo "${TmpVal##*/}"
index
 
echo "${FileName//\//+}"
+var+www+html+index.html

Description…

  • ${variable%pattern} removes first pattern on the right
  • ${variable%%pattern} removes last pattern on the right
  • ${variable#pattern} removes first pattern on the left
  • ${variable##pattern} removes last pattern on the left
  • ${variable/src/pattern} replace all entry

https://www.tldp.org/LDP/abs/html/string-manipulation.html

Только авторизованные участники могут оставлять комментарии.
  • blog/bash_manipulating_string.txt
  • Последние изменения: 2019/03/27