I'm running Ubuntu on WSL2. I frequently download zipped homework files from my school's website. They go into my Downloads folder on Windows. I want them copied into a particular path on my Linux filesystem, unzipped, and then renamed to put my name in front of the filename.
This is what I have so far:
params: $1: filename, $2: week_x, $3: day_y
hwcopy() {
cp $1 /home/myName/homework/$2/$3
rm -r $1
cd /home/myName/homework/$2/$3
unzip $1
}
I have a function addname
but the problem is if I call addname $1
, that will just rename the zipped folder.
Here's a solution I thought of:
hwcopy() {
cp $1.zip /home/myName/homework/$2/$3
rm -r $1.zip
cd /home/myName/homework/$2/$3
unzip $1.zip
addname $1
}
I suppose this would work, but it's a bit annoying because after autocompleting the file name for $1, I would need to hit backspace 4 times every time I wanted to call the function to get rid of the .zip in the argument. Is there a simple way to do this?
I'm new to Linux so I don't know how to do this but I was thinking maybe there's a way to save $1 as a string inside the function and then cut off the last 4 characters, and then pass that into everything else?