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
3 Answers 3
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
Comments
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.
Comments
directory Temp1 & Temp2
Temp1/
Temp2/a.sh
command to execute a.sh
$ . Temp1/Temp2/a.sh
I hope this is help you.
3 Comments
. Temp1/Temp2/a.sh don't execute a script but source it