I am trying to archive a file in a directory and use the filename of the file in the zip file name without knowing the filename. I have this command:

zip -FSmT (what to put here?).zip I805_test.txt

question is: how do I use the filename of I805_test.txt and create I805_test.txt.zip without knowing the input file name?

I think I need to use a system variable but I am not certain which one or how to implement.

1 Answer 1


Write a helper function (a wrapper). For instance,

function zip_this_file(){
   zip -FSmT "$1.zip" "$1"

This just takes a signle filename as an argument and performs what you want. Of course, you can make a proper wrapper and allow the user to pass options to zip, validate the arguments, check for existence of files and so on... it depends on what you want. If this will be needed in one single script, then leave it in that form. Otherwise, specify more clearly in what context you want to call this.

You must log in to answer this question.

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