The usual way to do this in bash is to use parameter expansion. (See the bash man page and search for "Parameter Expansion".)
a=${1%.*}
The % indicates that everything matching the pattern following (.*) from the right, using the shortest match possible, is to be deleted from the parameter $1. In this case, you don't need double-quotes (") around the expression.
The usual way to do this in bash is to use parameter expansion. (See the bash man page and search for "Parameter Expansion".)
a=${1%.*}
The % indicates that everything matching the pattern following (.*) from the right, using the shortest match possible, is to be deleted from the parameter $1. In this case, you don't need double-quotes (") around the expression.
If you know the extension, you can use basename
$ basename /home/jsmith/base.wiki .wiki
base
I want to extract the" name" of a filename without the extension- How do I use textscan to do this?
Correct way to remove all file extensions from a path with pathlib?
string - How do I get the filename without the extension from a path in Python? - Stack Overflow
Get image file extension
Videos
Python 3.4+
Use pathlib.Path.stem
>>> from pathlib import Path
>>> Path("/path/to/file.txt").stem
'file'
>>> Path("/path/to/file.tar.gz").stem
'file.tar'
Python < 3.4
Use os.path.splitext in combination with os.path.basename:
>>> os.path.splitext(os.path.basename("/path/to/file.txt"))[0]
'file'
>>> os.path.splitext(os.path.basename("/path/to/file.tar.gz"))[0]
'file.tar'
Use .stem from pathlib in Python 3.4+
from pathlib import Path
Path('/root/dir/sub/file.ext').stem
will return
'file'
Note that if your file has multiple extensions .stem will only remove the last extension. For example, Path('file.tar.gz').stem will return 'file.tar'.