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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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... :D -- 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 |
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 |
| All times are GMT. The time now is 06:26 PM. |
VBulletin, Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.