Mehdi
Mehdi

Reputation: 2228

How can i specify the Working directory from bash script

I want to run my java algorithm from bash script. When i run my program from Netbeans i can specify my Working directory from application. So, how can i specify the Working directory from bash script ?

Upvotes: 0

Views: 1382

Answers (1)

dafrito
dafrito

Reputation: 354

In Bash, you can just cd to the directory you'd like to work from. So, for example, if your app lives in ~/bin/app.jar, you'd have something like the following:

#!/bin/bash

WORKING_DIR=$HOME/lib # whichever directory you want to work from
cd $WORKING_DIR
java -jar ~/bin/app.jar

The trick is using an absolute path to your executable, or in this case, an absolute path to your Jar file.

Upvotes: 4

Related Questions