Ubuntu – Simple script – execute command on selected file

scripts

I want to make a script that will execute .jar file on selected file. Later I will add that script to right-click menu via the tool Nautilus Actions or just place it into nautilus-scripts folder. I have a problem creating script.

When I am in a usual console screen and want to execute this jar file on any other file, I use this syntax

myfile.jar ./someotherfile.xml

and the jar file will write the output to the console screen.

So I created a file script.sh, added lines in it

#!/bin/bash
/home/username/myfile.jar $1

But it does not output anything. I know I am doing something wrong. Please help.

To sum, I need a script that will use selected file as a parameter, open the gnome-terminal, inside that terminal it will start JAR file and pass it the selected file.

I am confident that this is a very simple procedure, but I am total newbie with shell scripting.

Best Answer

You might also go for

!/bin/sh
gnome-terminal -x java -jar /home/askmoo/myfile.jar "$1"

in order to first open gnome terminal and then execute your java application in it. This way you would be able to get output printed out to the terminal.

Related Question