It is possible to exec
at the specific folder, rather than I need to use two commands separately?
e.g.
cd /opt/folderA
exec ....
cd /opt/folderB
exec ....
It is possible to exec
at the specific folder, rather than I need to use two commands separately?
e.g.
cd /opt/folderA
exec ....
cd /opt/folderB
exec ....
The only ways to change current working directory for a process is:
a) the running program changes it by running a cd command from within the program itself
b) cd to the directory first and then run the program (inherits the CWD from the environment of the parent shell)
c) manipulate the /proc/[pid]/cwd file. The only way you could do this conceivably is by launching a separate bash shell, determine its pid, change the aforementioned file (a link), and then launch the program from within that bash shell.
So, to answer your question, there's no way around the "cd" command except option (c) which actually involves more steps than simply running "cd" first.
If this two commands are different you can add the folder to your $PATH environment.
export PATH=$PATH:folderA:folderB
Or you can use alias
alias fromA=/opt/folderA/command
alias fromB=/opt/folderB/command
after that you can directly use
fromA
Adding this to your .bashrc will make it permanently.