FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Redhat > Fedora User

 
 
LinkBack Thread Tools
 
Old 01-31-2011, 07:33 PM
Bruno Wolff III
 
Default OT: bash question

On Mon, Jan 31, 2011 at 12:32:24 -0800,
Mike Wright <mike.wright@mailinator.com> wrote:
> Hi all,
>
> Not sure where to find the answer to this question. Google wasn't
> helpful. The users on this list are a great repository of knowledge so
> I thought to try here.
>
> Is there a bash command that tells an executing script what *its* path
> is? Not the path where the user is but where the script is. If not
> that then a series of commands that yield the same result? Maybe some
> way of using 'ps'?
>
> Has me stumped and my dog-eared "UNIX in a Nutshell" hasn't exposed the
> goodies either

What is the high level purpose for wanting this information? There may be
other ways to solve that problem.
--
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
 
Old 01-31-2011, 07:55 PM
Mike Wright
 
Default OT: bash question

Bruno Wolff III wrote:
> On Mon, Jan 31, 2011 at 12:32:24 -0800,
> Mike Wright <mike.wright@mailinator.com> wrote:
>> Hi all,
>>
>> Not sure where to find the answer to this question. Google wasn't
>> helpful. The users on this list are a great repository of knowledge so
>> I thought to try here.
>>
>> Is there a bash command that tells an executing script what *its* path
>> is? Not the path where the user is but where the script is. If not
>> that then a series of commands that yield the same result? Maybe some
>> way of using 'ps'?
>>
>> Has me stumped and my dog-eared "UNIX in a Nutshell" hasn't exposed the
>> goodies either
>
> What is the high level purpose for wanting this information? There may be
> other ways to solve that problem.

Awesome, Bruno, thanks for responding.

I'm trying to create a self-contained app in that it is both a data
repository and also the location of its binary (BIN/runme, DATA/) so
that the application could be installed anywhere in user space and still
be able to find itself. A link in /usr/local/bin (wherever) would point
to the install location.

Ideas?

Mike



--
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
 
Old 01-31-2011, 08:06 PM
"Alan J. Gagne"
 
Default OT: bash question

You could try echo $0 from inside you script.
--
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
 
Old 01-31-2011, 08:08 PM
suvayu ali
 
Default OT: bash question

On Mon, Jan 31, 2011 at 12:32 PM, Mike Wright
<mike.wright@mailinator.com> wrote:
> s there a bash command that tells an executing script what *its* path
> is? *Not the path where the user is but where the script is.

$ cat ./test.sh
#!/bin/bash

echo $0 is the script
echo `dirname $0` is the script location

exit $?

HTH

--
Suvayu

Open source is the future. It sets us free.
--
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
 
Old 01-31-2011, 08:12 PM
Mike Wright
 
Default OT: bash question

Alan J. Gagne wrote:
> You could try echo $0 from inside you script.

Thanks Alan.

My mistake. I forgot to say that the file was invoked from a link.
Your proposed solution shows the link's location. I have to discover
the target of the link.

Ever onward!
--
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
 
Old 01-31-2011, 08:16 PM
Frantisek Hanzlik
 
Default OT: bash question

Mike Wright wrote:
> Alan J. Gagne wrote:
>> You could try echo $0 from inside you script.
>
> Thanks Alan.
>
> My mistake. I forgot to say that the file was invoked from a link.
> Your proposed solution shows the link's location. I have to discover
> the target of the link.
>
> Ever onward!

/bin/readlink from coreutils
--
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
 
Old 01-31-2011, 08:18 PM
Bruno Wolff III
 
Default OT: bash question

On Mon, Jan 31, 2011 at 12:55:36 -0800,
Mike Wright <mike.wright@mailinator.com> wrote:
>
> I'm trying to create a self-contained app in that it is both a data
> repository and also the location of its binary (BIN/runme, DATA/) so
> that the application could be installed anywhere in user space and still
> be able to find itself. A link in /usr/local/bin (wherever) would point
> to the install location.

That rules out doing some things with the fd directly, since that fd doesn't
point to the data.

If you know the program is being run via a sym link, then the readlink based
suggestions sound like they will do what you want.
--
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
 
Old 01-31-2011, 08:18 PM
"Alan J. Gagne"
 
Default OT: bash question

> My mistake. I forgot to say that the file was invoked from a link.
> Your proposed solution shows the link's location. I have to discover
> the target of the link.

echo `ls -la $0`
--
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
 
Old 01-31-2011, 08:22 PM
Mike Wright
 
Default OT: bash question

Frantisek Hanzlik wrote:
> Mike Wright wrote:
>> Alan J. Gagne wrote:
>>> You could try echo $0 from inside you script.
>> Thanks Alan.
>>
>> My mistake. I forgot to say that the file was invoked from a link.
>> Your proposed solution shows the link's location. I have to discover
>> the target of the link.
>>
>> Ever onward!
>
> /bin/readlink from coreutils

You are the man! Woooo Hoooo, that was the solution.

I knew this list had the masters...

--
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
 
Old 01-31-2011, 08:24 PM
Frantisek Hanzlik
 
Default OT: bash question

Alan J. Gagne wrote:
>> My mistake. I forgot to say that the file was invoked from a link.
>> Your proposed solution shows the link's location. I have to discover
>> the target of the link.
>
> echo `ls -la $0`

This will point only to first target. "readlink" has switches for
recursive resolv.
--
users mailing list
users@lists.fedoraproject.org
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
 

Thread Tools




All times are GMT. The time now is 05:32 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org