startScript.sh is in /root/script/startScript.sh
script1.shis in /root/script/test/script1.sh
script2.sh is in /root/script/test/script2.sh
startScript.sh looks like below
#!/bin/bash
#some code!
sh `pwd`/test/script1.sh 2>&1 &
sh `pwd`/test/script2.sh 2>&1 &
#some code
script2.sh and script1.sh look like below
#!/bin/bash
> `pwd`/process_ids.txt
while true;do
echo "The Process: `ps`" >> `pwd`/process_ids.txt
#some code to parse the process, etc. and echo it
done
Here is the thing is, the process_ids.txt file is creating in /root/script. But according to scriptx.sh the pwd is /root/scripts/test/. I displayed the pwd in scriptx.sh, it is showing /root/script/. How can I get the pwd of scriptx.sh?