Ubuntu – Nautilus script that creates a password protected ZIP

bashnautilusnautilus-script

In the latest versions of ubuntu, right clicking on a file doesn't give you the possibility to create password protected archives (see this question). I still need to do that kind of things though so I was trying to create a nautilus script that does the same job.

It's still very raw (I'm not very good with bash scripting) but it sort of works. The only problem is: it breaks if there is a space in a file name.

#!/bin/bash
files=""
for line in $@; do
    files+=" $line"
done

cd $NAUTILUS_SCRIPT_CURRENT_URI
gnome-terminal -t "Compressing File(s)" --hide-menubar -e "zip -r --encrypt compressed_file.zip $files"

How can I wrap the $line variable (line 4) to wrap the filename inside quotes?

edit: I could use file-roller instead of the shell zip command (it's even simpler indeed):

#!/bin/bash

file-roller -d $@

But still, I have to wrap the file names into quotes in order to avoid problems

Best Answer

Try this:

#!/bin/bash

file-roller -d "$@"

Putting quotes around $@ makes it handle spaces correctly.

Related Question