I'm probably missing something basic with bash function variable syntax here.

My understanding of the zip command's syntax is that it's zip newfilename.zip filetobezipped. So I want my function to zip the specified folder and all its contents, and I want the result, zipped folder to be named the same name as the contents, just with .zip added. Then I copy that over to my windows directory and delete it from the linux directory.

To be clear, if the file I want zipped is called "something", then I want the zipped version to be named "something.zip".

However, this function produces a hidden zip file, .zip with no letters before the period. So it seems my variable $1 is not being passed into the function correctly.

params: $1: filename, $2: week_x, $3: day_y
hwcopy() {
    zip -r $1.zip $1
    cp $1.zip /mnt/c/Users/myName/Desktop/homework/$2/$3
    rm -r $1.zip

How I called it (from within the parent directory): $ hwcopy file_folder_name/ week_x day_5


1 Answer 1


I realized after testing more that the issue was the way I called it.

zip file_name/.zip file_name won't work, but zip file_name.zip file_name will work.

So I instead referred to it as ${1%/}.zip inside the function, to cut off the slash character.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .