1

how can i execute a script that is placed in a different directory,

so i do not have to CD into that directory?

the file that the script works on is placed in the same same directory as the script

is it possible to use absolute path names?

to make it clear...i do not have two scripts. to put it more detailed:

i want to replace a command that changes into a directory with a file and a script in it. the script is executed and changes the data format of the file, e.g.:

CD targetdirectory && script file 

now i want to do the same without having to CD into that directory so i thought i could just do this:

/pathtomyscript.sh file 

is this possible? and the other question is, do i have to use an absolute path name for the file as well e.g.:

/pathtomyscript.sh /pathtomyfile 
asked Jan 5, 2015 at 16:29

3 Answers 3

2

What you can do :

1) ensure the 2th script have eXecutable bit

chmod +x script2.sh

2) put relative or full path of the script, like

../../script2.sh # 2 dirs up

or

/full/path/to/my/script2.sh
answered Jan 5, 2015 at 16:44
Sign up to request clarification or add additional context in comments.

Comments

0

So assuming you have two scripts like:

$ ls
 script1.sh
 script2.sh

And now if you want to run script2.sh from script1.sh, you could just have ./script2.sh in the script1.sh. Make sure you have execute permission for your script2.sh.

answered Jan 5, 2015 at 16:40

Comments

0

directory Temp1 & Temp2

 Temp1/
 Temp2/a.sh

command to execute a.sh

 $ . Temp1/Temp2/a.sh

I hope this is help you.

answered Jan 5, 2015 at 16:46

3 Comments

. Temp1/Temp2/a.sh don't execute a script but source it
we can use bash temp1/temp2/a.sh
This is the better way... to have conflicting bash, *sh version, but it's better, yes.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.