Mert Saraçoğlu Mert Saraçoğlu - 2 months ago 6x
Bash Question

Something like environment variable in Ubuntu

I'm new to Linux and Ubuntu environment.

I'm calling a jar file like this :

java -jar app.jar /somearg /anotherarg

But I find this ugly and I want to call my jar file like :

MyApp /somearg /anotherarg

So I think I have to set a environment variable like
MyApp = java -jar app.jar

But I don't know how can I do it.If anyone can help me I'll be very pleased.Thanks.



java -jar app.jar /somearg /anotherarg

instead of

myapp /somearg /anotherarg

saves you only 2 words, so not that much. Anyway if you run your application frequently it is a good idea to provide an alias. If you are using bash shell (echo $SHELL shows something like /bin/bash) then here's the command you can paste in your terminal:

alias myapp="java -jar /path/to/your/app/app.jar"

After that you can use

myapp /somearg /anotherarg

It is important to provide the whole path to your app.jar file if you run it from different locations. Also if you want that your alias is permament (i.e. it is always after you log in) just add the same line at the end of ~/.bashrc file, using for example:

pico ~/.bashrc

PS. You don't need slash symbol to provide parameters. In unix systems it is more common to use "-" to set argument options.

PSS. Unix systems are case sensitive and it is typical that command line programs are all written in lowercase.