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?
pwdreturns) of the script, but the location of the script itself. See http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in, http://unix.stackexchange.com/questions/17717/refer-to-a-file-under-the-same-directory-of-a-script-found-in-path – muru Nov 26 '15 at 13:20