4

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

ToX 82
  • 391
  • 1
    FileManager-Actions (previously known as Nautilus-Actions) may help to get ready-to-use solution - see https://askubuntu.com/a/1031746/66509 . – N0rbert Jun 22 '18 at 09:36
  • 2
    @N0rbert That answer followed by this Q&A should solve this problem then. – pomsky Jun 22 '18 at 09:54
  • Using nautilus-actions is a way to get around the problem, but if I can solve the quotes thing it wouldn't even be needed: Instead of the gnome-terminal - t... application I could launch file-roller -d $files and launch file roller instead of a terminal script. The problem is, without wrapping every file inside quotes, if there is a space in a filename it would be skipped... I'd like to fix that – ToX 82 Jun 22 '18 at 10:08

1 Answers1

0

Try this:

#!/bin/bash

file-roller -d "$@"

Putting quotes around $@ makes it handle spaces correctly.