Re: bash question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 02/01/2011 05:23 AM, fedora wrote:
> dirname $0
> 
> suomi
> 
> On 2011-02-01 13:03, Patrick O'Callaghan wrote:
>> On Mon, 2011-01-31 at 14:49 -0700, compdoc wrote:
>>>> Is there a bash command that tells an executing script what *its* path is?
>>>
>>> echo $PWD
>>
>> No, that just tells where it was executed from. The OP wants to know
>> where the script actually lives.
>>
>> poc
>>

The value of $0 on a Linux system will be the full path to where the
script was found, so 'dirname $0' works.

However, bash runs on other OS's (Solaris for one), and Solaris does not
provide the full path in $0, you only get the name of the script.

So be careful if you're writing code that needs to be portable.

-- 
Bob McGowan
-- 
users mailing list
users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines

[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [EPEL Devel]     [Fedora Magazine]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Desktop]     [Fedora Fonts]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Fedora Sparc]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux