#!/bin/bash
fullpath="/etc/nginx/nginx.conf"
filename=$(basename "$fullpath")
echo $filenamenginx.confDrop the extension
#!/bin/bash
fullpath="/etc/nginx/nginx.conf"
filename=$(basename "$fullpath")
fname="${filename%.*}"
echo $fnamenginxJust the extension
#!/bin/bash
fullpath="/etc/nginx/nginx.conf"
filename=$(basename "$fullpath")
ext="${filename##.*}"
echo $extconfFor more details, check shell parameters expansion in Bash manual.
In general,
${variable%pattern}- Trim the shortest match from the end${variable##pattern}- Trim the longest match from the beginning${variable%%pattern}- Trim the longest match from the end${variable#pattern}- Trim the shortest match from the beginning