|
Home > Archive > Unix Shell > November 2007 > shell script source getting actual path problem
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
shell script source getting actual path problem
|
|
|
| I am facing this problem:
I have two scripts, for example:
/home/usr1/dir1/script1
and
/home/usr1/dir2/script2
script1 contains the line:
source /home/usr1/dir2/script2
I am editing script2 and need to know its actual path without editing
script1 -for example sending parameters-
Thanks,
Amr Bedair
| |
| Cyrus Kriticos 2007-11-26, 7:21 pm |
| mero wrote:
>
> I have two scripts, for example:
>
> /home/usr1/dir1/script1
> and
> /home/usr1/dir2/script2
>
> script1 contains the line:
>
> source /home/usr1/dir2/script2
>
> I am editing script2 and need to know its actual path without editing
> script1 -for example sending parameters-
with bash version >= 3.0:
MYLOCATION="${PWD}/${BASH_ARGV[0]}"
export MYLOCATION="${MYLOCATION%/*}"
--
Best regards | (\_/)
Cyrus | (O.o) This is Bunny. Copy Bunny into your signature
| (> < ) to help him on his way to world domination.
| |
| Cyrus Kriticos 2007-11-26, 7:21 pm |
| Cyrus Kriticos wrote:
> mero wrote:
>
> with bash version >= 3.0:
>
> MYLOCATION="${PWD}/${BASH_ARGV[0]}"
> export MYLOCATION="${MYLOCATION%/*}"
correction:
with bash version >= 3.0:
echo ${BASH_ARGV[0]}
--
Best regards | (\_/)
Cyrus | (O.o) This is Bunny. Copy Bunny into your signature
| (> < ) to help him on his way to world domination.
| |
|
| On Nov 26, 10:06 pm, Cyrus Kriticos <cyrus.kriti...@googlemail.com>
wrote:
> Cyrus Kriticos wrote:
>
>
>
>
>
>
>
>
> correction:
> with bash version >= 3.0:
>
> echo ${BASH_ARGV[0]}
>
> --
> Best regards | (\_/)
> Cyrus | (O.o) This is Bunny. Copy Bunny into your signature
> | (> < ) to help him on his way to world domination.
is there any way to do this on :
GNU bash, version 2.05b
Thanks,
Amr Bedair
| |
|
| On Nov 26, 11:52 pm, mero <AmrBed...@gmail.com> wrote:
> On Nov 26, 10:06 pm, Cyrus Kriticos <cyrus.kriti...@googlemail.com>
> wrote:
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> is there any way to do this on :
> GNU bash, version 2.05b
>
> Thanks,
> Amr Bedair
Also i need to know please what to do for KSH
Thanks
| |
| Chris F.A. Johnson 2007-11-26, 7:21 pm |
| On 2007-11-26, mero wrote:
>
> I am facing this problem:
>
> I have two scripts, for example:
>
> /home/usr1/dir1/script1
> and
> /home/usr1/dir2/script2
>
> script1 contains the line:
>
> source /home/usr1/dir2/script2
>
> I am editing script2 and need to know its actual path without editing
> script1 -for example sending parameters-
grep 'source.* /script2' /home/usr1/dir1/script1
--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell/>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
| |
| Maxwell Lol 2007-11-27, 7:33 am |
| mero <AmrBedair@gmail.com> writes:
>
> I am editing script2 and need to know its actual path without editing
> script1 -for example sending parameters-
I like to use environment variables for issues like this.
| |
|
| On Nov 27, 1:42 am, "Chris F.A. Johnson" <cfajohn...@gmail.com> wrote:
> On 2007-11-26, mero wrote:
>
>
>
>
>
>
>
> grep 'source.* /script2' /home/usr1/dir1/script1
>
> --
> Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell/>
> Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
> ===== My code in this post, if any, assumes the POSIX locale
> ===== and is released under the GNU General Public Licence
the problem is that i actually do not know the caller, also it may be
more than one caller
Thanks.
| |
|
| On Nov 27, 2:22 pm, Maxwell Lol <nos...@com.invalid> wrote:
> mero <AmrBed...@gmail.com> writes:
>
>
> I like to use environment variables for issues like this.
Please, can you explain how to do that?
Thanks
| |
|
| On Nov 27, 2:22 pm, Maxwell Lol <nos...@com.invalid> wrote:
> mero <AmrBed...@gmail.com> writes:
>
>
> I like to use environment variables for issues like this.
Please, can you explain how to do that?
Thanks
| |
|
| On Nov 27, 2:22 pm, Maxwell Lol <nos...@com.invalid> wrote:
> mero <AmrBed...@gmail.com> writes:
>
>
> I like to use environment variables for issues like this.
Please, can you explain how to do that?
Thanks
| |
|
| On Nov 27, 2:22 pm, Maxwell Lol <nos...@com.invalid> wrote:
> mero <AmrBed...@gmail.com> writes:
>
>
> I like to use environment variables for issues like this.
Please, can you explain how to do that?
Thanks
| |
|
| On Nov 27, 2:22 pm, Maxwell Lol <nos...@com.invalid> wrote:
> mero <AmrBed...@gmail.com> writes:
>
>
> I like to use environment variables for issues like this.
Please, can you explain how to do that?
Thanks
| |
|
| mero <AmrBed...@gmail.com> wrote:
> mero <AmrBed...@gmail.com> wrote:
> Also i need to know please what to do for KSH
See my [ksh and presumably bash] function "resolvepath":
http://groups.google.com/group/comp...3b2b4fef10d3717
However, a perpetual implementation feature of sourced scripts/
functions (at least in ksh) is that the file argument is liable to a
path lookup. With a little care in controlling PATH, you can let
the system resolve the system pathname, without bothering to
hardwire in fully qualified pathnames into scripts.
PATH=/path/to/scripts . script2 # sources "script2" wherever it exist
in PATH
PATH=/path/to/scripts command . script2 # same, but keeps old PATH
Autoloading (RTFM) is especially appropriate for this purpose.
I understand this doesn't help you now, with a script that you
cannot edit.
=Brian
| |
| Maxwell Lol 2007-11-28, 1:42 am |
| mero <AmrBedair@gmail.com> writes:
> On Nov 27, 2:22 pm, Maxwell Lol <nos...@com.invalid> wrote:
>
> Please, can you explain how to do that?
Well, if the location of scripts can be in different positions,
the best thing to do is to use a variable that specifies where they are.
Let's say you want to execute /usr/local/bin/MyScript
but it might be in /home/local/bin/MyScript, then just use
${MYSCRIPT='/usr/local/bin'}/MyScript
And then you can, if you want, source a file that has
MYSCRIPT=/home/local/bin
Let's say this file is called ~/.myscript
You can make it unique per user using some code like
----------------------------
if [ -f ~/.myscript ]
then
. ~/.myscript
fi
${MYSCRIPT='/usr/local/bin'}/MyScript
----------------------------
This can be a global script.
The user can either create a startup file called ~/.myscript
or can set an environment variable overriding the default value of MYSCRIPT
Or they can do nothing.
|
|
|
|
|