How can I remove the extension of a filename in a shell script?

What’s wrong with the following code?

name="$filename | cut -f1 -d".''

As is, I get the literal string $filename | cut -f1 -d'.', but if I remove the quotes I don’t get anything. Meanwhile, typing

"test.exe" | cut -f1 -d'.'

in a shell gives me the output I want, test. I already know $filename has been assigned the right value. What I want to do is assign to a variable the filename without the extension.

15 Answers
15

Leave a Comment