Step-by-Step descriptions of how to do things.
-
^rooker
- Site Admin
- Posts: 1483
- Joined: Fri Aug 29, 2003 8:39 pm
Post
by ^rooker »
A clean way for removing a file suffix (.jpg, .txt, ...) using only bash-internal syntax is as follows:
Code: Select all
FILE="bla.txt"
NAME="${FILE%.*}"
echo $NAME
This will output:
bla
Jumping out of an airplane is not a basic instinct. Neither is breathing underwater. But put the two together and you're traveling through space!
-
peter_b
- Chatterbox
- Posts: 383
- Joined: Tue Nov 12, 2013 2:05 am
Post
by peter_b »
Here's the opposite of ^Rooker's snippet:
How to extract the file suffix as string in Bash?
Code: Select all
FILE="bla.txt"
NAME="${FILE##*.}"
echo $NAME
This will output:
txt