bash remove extension 1

bash remove extension

$ filename=foo.txt
$ echo "${filename%.*}"

Here is what the above code is Doing:
1. The % operator is used to remove the shortest match of the pattern from the end of the string.
2. The pattern is given as .* which matches any character (.) zero or more times (*).
3. The pattern is enclosed in double quotes to prevent the shell from expanding it.

Similar Posts