You can do like this (in bash v4 and higher):
#!/bin/bash
v="some string.rtf"
v2=${v::-4}
echo "$v --> $v2"
Note: macos uses bash 3.x by default
More Related Contents:
- Reading quoted/escaped arguments correctly from a string
- Can a shell script set environment variables of the calling shell? [duplicate]
- How to pass a variable containing slashes to sed
- How can I remove the extension of a filename in a shell script?
- While-loop subshell dilemma in Bash
- Variables in bash seq replacement ({1..10}) [duplicate]
- Bash script – store stderr in a variable [duplicate]
- How can I count all the lines of code in a directory recursively?
- How does Ctrl-C terminate a child process?
- Running multiple commands in one line in shell
- Why source command doesn’t work with process substitution in bash 3.2?
- Specify other flags in awk script header
- echo that outputs to stderr
- Variable variable assignment error -“command not found”
- Concatenating multiple text files into a single file in Bash
- find files older than X days in bash and delete
- How to Batch Rename Files in a macOS Terminal?
- How to pass arguments to Shell Script through docker run
- Simulate user input in bash script [closed]
- Print a character repeatedly in bash [duplicate]
- Forking / Multi-Threaded Processes | Bash
- BASH Syntax error near unexpected token ‘done’ [duplicate]
- Why is #!/usr/bin/env bash superior to #!/bin/bash?
- In what order should I send signals to gracefully shutdown processes?
- Bash regex =~ operator
- Using sed to insert file content
- bash script order of execution
- Why doesn’t **sort** sort the same on every machine?
- bash piping prevents global variable assignment
- Groups of compound conditions in Bash test [duplicate]