Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have a bat file that I want to be able to call from everywhere, by simply calling it's name. In windows I simply had to add the folder where the .bat file is located, to the windows PATH. I have no idea how to do this in Ubuntu though. I'm guessing there's something similar..

Can someone explain how to do this.

share|improve this question

4 Answers 4

up vote 4 down vote accepted

if you want to shortcut the program, and leave it where it is you can either use sym. links or the alias command.

(note this assumes you've made it executable, chmod +x [script file])

sym links allow you to create a shortcut that behaves like the file in question.

sudo ln -s [script start-up file] /usr/bin/[name]

despite being in /usr/bin it will start in the directory you call it from.

alias allows you to give an name to a command, or series of piped commans, that you use regually, for example its fairly common to have the update/upgrade commands combined into a single, alias'd, one.

alias [name]="sh /path/to/script/[file name]"

assuming that your script runs with sh, (this could also be bash, for more complex tasks there is a difference).

share|improve this answer
    
+1 I use symlinks alot and forgot about them in my answer :D –  Rinzwind Jun 4 '11 at 16:56

First of all, there are no bat files for ubuntu, maybe you mean script files.

If you create a bin directory under your home, this will be automatically added to your PATH. Remember to give execution permissions to your scripts.

share|improve this answer

I use a folder in my home directory for this: ~/.local/bin

That way, it's out of sight and all binary files that aren't system-wide I put in there, like small personal scripts that only I will be interested in running.

This method is also helpful for users who do not have system administrator permissions.

The PATH environment variable works in much the same way as it does on Windows, except paths are separated using colon (:) instead of semi-colon (;).

So, in short, run the following in a terminal (where "$" is the prompt):

$ mkdir -p ~/.local/bin
$ mv /path/to/executable/file ~/.local/bin/

then add the following line to your ~/.bashrc file (if you are running Bash as your shell):

export PATH=$HOME/.local/bin:$PATH

If you are running a different shell, this final step may vary for you.

share|improve this answer

Executables should be in /usr/bin so that solves your problem since this is inside your environment.

You can set a file to executable with the chmod command (sudo chmod 775 {filename}). More info on the permissions wiki page.

The Ubuntu wiki on Environment variables will explain a lot about how settins can be set but there is no need for using this with just 1 script (Linux already got that covered).

share|improve this answer
    
Well this file depends on other files as well (it creates projects actually) so it would be easier if I could just leave it in my documents folder. Is there any way to do that? –  Sled Jun 4 '11 at 16:21
    
@sled sure! have a look at the Environment variables like I put in my answer. For example /etc/environment contains the system wide path. But there are more places to set a dir. But what you intend is more a windows way then a linux way ;) Security wise you should follow Linux's method. –  Rinzwind Jun 4 '11 at 16:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.