Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove postfix from a string in bash?

I want to to this in shell-script: remove the file postfix and save it into another variable:

file=abcabc.cpp
postf=.cpp
name=${file##postf}
echo $name

But this couldn't work. I want name=abcabc after the operation. Can you help me?

like image 546
Lex Pro Avatar asked Jan 28 '15 06:01

Lex Pro


1 Answers

You can use:

name="${file%$postf}"
echo "$name"
abcabc
like image 186
anubhava Avatar answered Oct 14 '22 09:10

anubhava