Reputation: 4410
for example
echo "filename.pdf" | cut -d'.' -f 1
This way I get the "filename" string. I'd like to store it in a variable called FILE and then use it like this:
DIR=$PATH/$FILE.txt
So, my script wants to create a file.txt with the same name of the pdf (not a copy of the file, just the name) This way I tried to assign the result of echo | cut
FILE=
but I get only "path/.txt" so the filename is missing.
Upvotes: 3
Views: 20980
Reputation: 531055
POSIX parameter expansion would read
file=filename.pdf
filename="${file%%.*}" # Two % will remove multiple extensions, if applicable
dir=$path/$filename.txt
Upvotes: 2
Reputation: 785058
So, my script wants to create a file.txt with the same name of the pdf
You can use BASH string manipulation:
s="filename.pdf"
p="${s/%.pdf/.txt}"
echo "$p"
filename.txt
Upvotes: 2