0

My script is:

/opt/Myapplication/bin/start.sh

I always have to start it this way:

$cd /opt/Myapplication
$bin/start.sh

Now I want to write a script, which will run start.sh as above. I mean, it should run it from /opt/Myapplication directory

Maybe like this:

#!/bin/bash

my_path=/opt/Myapplication
$my_path/bin/start.sh

Will it run start.sh from /opt/Myapplication directory?

2 Answers 2

1

it will run /opt/Myapplication/my_path/bin/start.sh, but it won't change the working directory, if that's what you mean. To do that, you'll have to cd in the script first:

#!/bin/bash

my_path=/opt/Myapplication
cd $my_path
$my_path/bin/start.sh
Sign up to request clarification or add additional context in comments.

2 Comments

maybe ./bin/start.sh in last line?
that doesn't really make any difference, it just uses the relative path instead of the absolute, the result is the same.
0

You want to avoid scripts that need to be in a specific location to work properly

But no it will not run with that working directory, you have to cd first

#!/bin/bash
cd /opt/Myapplication/bin
bash start.sh

2 Comments

No, I must run it from /opt/Myapplication directory.
Use a subshell if you want to avoid cwd pollution: (cd /opt/Myapplication && ./start.sh)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.