This question already has an answer here:
- How do ${0##*/} and ${0%/*} work? 1 answer
Consider the following bash script:
#!/bin/bash
echo "${1##*.}"
This script prints the extension of a file if the file name is supplied as the first command line argument, something like following:
$ ./script.sh ./file.pdf
In the above case pdf
is printed.
Please explain how the expression ${1##*.}
is able to extract the extension of the file.
(I understand what $0, $1, $2, $# do in bash and also understand about regular expressions to some extent)