Fish Practice
tldr
string replace FROM TO inputstring split SEP input
What is this about
I’ve been switching to fish for a while. The reason I switched was because I wanted to be able to comfortably write for loops in the interactive shell, utilize various string functions. Unfortunately the only thing I got used to is to do ctrl-f to autocomplete. This is a small drill I came up with to try to improve a little using fish
The adhoc drill
- Generate files from a.txt to z.txt
- Rename all from *.txt to *.yo.txt
- Replace all *.yo.txt to *.sup.txt
Step 1: Generate files from a.txt to z.txt
This step took me a bit longer than I expected.
Turns out there is no simple way in fish to generate a to z.
the fish native way would be string split "" "abcdefghijklmnopqrstuvwxyz"
to tap into bash it would be bash -c "echo {a..z}"
Let’s go with bash
|
|
Now I want to for loop $xs and create the .txt files
Step 2: Rename all from *.txt to *.yo.txt
This step was nice, string split splits a.txt into a txt, and since fish is 1-based index, I set name to the filename without the extension.
Then it’s the mv command
Step 3: Rename all from *.yo.txt to *.sup.txt
I could do the same trick, pull out the name and manually write the sup part in mv, but instead I wanted to try out string replace