Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

fish

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?

like image 435
codehitman Avatar asked Jul 26 '16 12:07

codehitman


People also ask

How do I batch rename a file extension?

How to batch rename extensions. Navigate to the folder containing the files you want. Once there, launch command prompt from the folder menu by holding down shift and right clicking on an empty space. Once in command prompt, you can now use the ren (for rename) command to rename for example, .

How do you rename a file extension in Python?

Sometimes you might want to rename the extension of your file and this can be quickly done using rename() method in Python. This can be done by selecting the file and then getting only the file name using the splitext() method of the os module. This method returns the root and extension separately.

How do you rename a file extension in Linux?

Extensions are part of a file's name. And if you want to change the extension (or the name), you'd use the mv command. mv stands for "move" and is the standard command on Linux for moving and renaming files.


1 Answers

To do this just with fish:

for j in *.md
    mv -v -- $j (string replace -r '\.md$' .txt $j)
end
like image 145
glenn jackman Avatar answered Oct 11 '22 19:10

glenn jackman