Saturday 25 January 2014

Linux - How To Create a Batch File

The final step - making the shell script "executable"
Back in the days of DOS I used to make batch files all the time, in fact I still do in Windows even today.

I wanted to know how to do this in Linux. Right now I have to launch KeePass by typing each time:

mono /home/me/KeePass/KeePass.exe

It's not too much of a pain but I want to save any time where I can. The more convenient it is to reach my tools, the more and better I'll use them.

So I've read up and things work a little different in Linux.

I already knew I needed to make a "shell script". I've seen these marked with ".sh" and even tried to make my own earlier but it didn't work. Unlike DOS/Windows, the extension does not change the way the file is treated. In fact ".sh" is just used as a nice way of telling the user what kind of file it is. I'll tell you how to tell the OS what to do in a minute.

First I start by opening gedit, the text editor.

Then I type the following:

#! /bin/bash
mono /home/me/KeePass/KeePass.exe

Then save it with whatever name I want. Finally, I right-click it, Properties, Permissions tab then check "Allow this file to run as a program". That tells the OS what to do with it. There is a terminal method to do this called "chmod" but I need to read up on it again on exactly how it works.

That's it, now this file will execute as if I were typing that second line directly in a Terminal window.

No comments:

Post a Comment

Popular Posts