![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| full system backup script | clement | Linux | 5 | 11-26-2007 11:23 PM |
| script sourcing problem (ksh) | rakeshou | UNIX for Dummies Questions & Answers | 3 | 09-21-2007 06:29 AM |
| getting full path from relative path | polypus | Shell Programming and Scripting | 4 | 03-25-2007 09:08 AM |
| Full path of executing script in ksh? | BriceBu | Shell Programming and Scripting | 2 | 09-19-2005 06:29 AM |
| Full-Screen Script | Morcegao30 | Shell Programming and Scripting | 1 | 03-01-2005 12:49 AM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Maintain full path of a script in a var when sourcing it from a different script
Hi All,
I've searched through the forum for a solution to this problem, but I haven't found anything. I have 2 script files that are in different directories. My first script, let's call it "/one/two/a.sh" looks like this: Code:
#!/bin/sh IN_DIR=`dirname $0` CUR_DIR=`pwd` cd $IN_DIR A_DIR=`pwd` cd $CUR_DIR export $A_DIR echo $A_DIR Now I have a second script in a different directory that sources this script. Let's call it "/hello/bye/b.sh" Code:
#!/bin/sh . /one/two/a.sh echo $A_DIR I guess this is because the $0 variable inside the first script becomes "b.sh" instead. I want the first script to always source the $A_DIR variable with the path of the script, and I do not want to rely on hard-coding it, nor using the "find" command. Does anyone have any ideas? Any help would be great! Thanks in advance! |
| Forum Sponsor | ||
|
|
|
|||
|
Hi Jim, thanks for the reply.
I make some change directory calls inside a.sh, so that the pwd becomes dirname ${0}. The problem I think is that, I'm not invoking a.sh, but sourcing it inside b.sh: Code:
#!/bin/sh . /one/two/a.sh echo $A_DIR /hello/bye/b.sh Because a.sh makes the following call: dirname ${0}. It gets the path of the current value inside $0, which is actually "/hello/bye/b.sh", since that script is the one being actually invoked. |
|
||||
|
Quote:
|
||||
| Google UNIX.COM |