Please support our Shell Scripting advertiser: Programming Forums
Views: 2603 | Replies: 3
![]() |
•
•
Join Date: Mar 2006
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
I have a shell script, /path/adir/script1.sh, that calls another script, /path/bdir/script2.sh. Now, I am in the directory /path/cdir/, and I call the first script like this:
../adir/script1.sh
The problem is that script2.sh cannot be found. In fact, even if script2.sh is in the same directory as script1.sh, the same problem occurs. The file script1.sh looks like this:
...
./script2.sh
...
How can I fix it? Thanks in advance.
../adir/script1.sh
The problem is that script2.sh cannot be found. In fact, even if script2.sh is in the same directory as script1.sh, the same problem occurs. The file script1.sh looks like this:
...
./script2.sh
...
How can I fix it? Thanks in advance.
•
•
Join Date: Mar 2006
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
I realized I didn't make myself clear enough: I don't want to call script2.sh in the following way:
../bdir/script2.sh
because script1.sh could be called from any other directory and the above way won't work. However, it can be assumed that these two scripts are in their relative directories (though their parent directory may differ).
../bdir/script2.sh
because script1.sh could be called from any other directory and the above way won't work. However, it can be assumed that these two scripts are in their relative directories (though their parent directory may differ).
•
•
Join Date: Dec 2003
Location: Nashville, TN
Posts: 2,336
Reputation:
Rep Power: 12
Solved Threads: 102
•
•
Join Date: Apr 2006
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
You can get the path of your script with $0 :
or, to get absolute path :
So, put the few lines above in script1.sh
And call script2 with :
SCRIPT_DIR=`dirname $0` #relative path or, to get absolute path :
INITIAL_DIR=`pwd` # Save current dir
cd `dirname $0` # Go to script dir
SCRIPT_DIR=`pwd` # Save script dir
cd ${INITIAL_DIR} # Go back to initial directory So, put the few lines above in script1.sh
And call script2 with :
${SCRIPT_DIR}/script2.sh ![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)






Linear Mode