Search code examples
fish

How to rename file extentions in fish in a for loop?


Here is the equivalent bash script that I am trying to convert to fish:

for j in *.md; do mv -v -- "$j" "${j%.md}.txt"; done

Here is what I tried:

for file in *.md
    mv -v -- "$file" "{{$file}%.md}.txt"
end

But it simply ends up renaming all of the files like so:

‘amazon.md’ -> ‘{{amazon.md}%.md}.txt’

How do I do this correctly?


Solution

  • I found an alternative solution to this:

    for file in *.md
        mv -v -- "$file" (basename $file .md).txt 
    end
    

    It works like a charm!