How to get filename without the extension in Fish script?
·
158 words
·
1 minute read
We can use string split like this (string split -r -m1 . $filename)[1]
.
I use this method in my Fish script function.
function vidfps --description "vidfps <input.mp4>"
ffmpeg -i $argv -filter:v fps=fps=24 (string split -r -m1 . $argv)[1]-24fps.mp4
end
The above function is located in my ~/.config/fish/config.fish
file. So I can use it to convert a video to a 24 frames-per-second video using ffmpeg. the code (string split -r -m1 . $argv)[1]
give me the filename without extension. But if I want to get the extension itself, I can use this code (string split -r -m1 . $argv)[2]
.
If the path has folders or directories and you want to strip them out, to get only the file name, use this code (basename $filename | string split -r -m1 .)[1]
.
I hope this helps you. You know someone will benefit from this, share it with him/her, a friend or colleage.
Read more: