<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How do I script the directory in which this script is located? in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/how-do-i-script-the-directory-in-which-this-script-is-located/m-p/3449241#M708044</link>
    <description>i've always used:&lt;BR /&gt;program="${0:##*/}"&lt;BR /&gt;path="${0:%/*}"&lt;BR /&gt;&lt;BR /&gt;for posix type shells</description>
    <pubDate>Wed, 22 Dec 2004 18:39:54 GMT</pubDate>
    <dc:creator>c_51</dc:creator>
    <dc:date>2004-12-22T18:39:54Z</dc:date>
    <item>
      <title>How do I script the directory in which this script is located?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-do-i-script-the-directory-in-which-this-script-is-located/m-p/3449235#M708038</link>
      <description>We have scripts that we move around from machine to machine.  &lt;BR /&gt;&lt;BR /&gt;They can be in:&lt;BR /&gt;/usr/local/bin/&lt;BR /&gt;/opt/local/bin/&lt;BR /&gt;/usr/contrib/bin&lt;BR /&gt;&lt;BR /&gt;How can I script definitively where they are from within the script.  You can't just go $PWD, because if that will give you where you are sitting right now.  You can't go "whence" because that may turn up more than one of them.  Also, the location may be some other place not in your path. &lt;BR /&gt;&lt;BR /&gt;I think that you can use some combination of "basename" or "dirname" or something like that.</description>
      <pubDate>Wed, 22 Dec 2004 15:00:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-do-i-script-the-directory-in-which-this-script-is-located/m-p/3449235#M708038</guid>
      <dc:creator>Stuart Abramson</dc:creator>
      <dc:date>2004-12-22T15:00:30Z</dc:date>
    </item>
    <item>
      <title>Re: How do I script the directory in which this script is located?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-do-i-script-the-directory-in-which-this-script-is-located/m-p/3449236#M708039</link>
      <description>in script:&lt;BR /&gt;&lt;BR /&gt;which $0</description>
      <pubDate>Wed, 22 Dec 2004 15:04:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-do-i-script-the-directory-in-which-this-script-is-located/m-p/3449236#M708039</guid>
      <dc:creator>Tom Danzig</dc:creator>
      <dc:date>2004-12-22T15:04:00Z</dc:date>
    </item>
    <item>
      <title>Re: How do I script the directory in which this script is located?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-do-i-script-the-directory-in-which-this-script-is-located/m-p/3449237#M708040</link>
      <description>EDIT:  If you only want the directory, use:&lt;BR /&gt;&lt;BR /&gt;dirname `which $0`</description>
      <pubDate>Wed, 22 Dec 2004 15:15:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-do-i-script-the-directory-in-which-this-script-is-located/m-p/3449237#M708040</guid>
      <dc:creator>Tom Danzig</dc:creator>
      <dc:date>2004-12-22T15:15:58Z</dc:date>
    </item>
    <item>
      <title>Re: How do I script the directory in which this script is located?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-do-i-script-the-directory-in-which-this-script-is-located/m-p/3449238#M708041</link>
      <description>I think that "which" only works for c shell users.  It takes the path/environment from .cshrc.&lt;BR /&gt;&lt;BR /&gt;Since I'm a ksh user, it doesn't work for me.  It says "no xxxx in and lists my path (correctly - but it can't find xxxx which is right there in the path.)</description>
      <pubDate>Wed, 22 Dec 2004 15:46:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-do-i-script-the-directory-in-which-this-script-is-located/m-p/3449238#M708041</guid>
      <dc:creator>Stuart Abramson</dc:creator>
      <dc:date>2004-12-22T15:46:36Z</dc:date>
    </item>
    <item>
      <title>Re: How do I script the directory in which this script is located?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-do-i-script-the-directory-in-which-this-script-is-located/m-p/3449239#M708042</link>
      <description>which SHOULD work for any shell in HP-UX.  A better option may actually be to use whence.&lt;BR /&gt;&lt;BR /&gt;# whence xxxx</description>
      <pubDate>Wed, 22 Dec 2004 15:50:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-do-i-script-the-directory-in-which-this-script-is-located/m-p/3449239#M708042</guid>
      <dc:creator>Patrick Wallek</dc:creator>
      <dc:date>2004-12-22T15:50:29Z</dc:date>
    </item>
    <item>
      <title>Re: How do I script the directory in which this script is located?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-do-i-script-the-directory-in-which-this-script-is-located/m-p/3449240#M708043</link>
      <description>/usr/bin/which should work for any shell.  whence is actually a shell built-in and would not be available in csh.</description>
      <pubDate>Wed, 22 Dec 2004 15:53:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-do-i-script-the-directory-in-which-this-script-is-located/m-p/3449240#M708043</guid>
      <dc:creator>Tom Danzig</dc:creator>
      <dc:date>2004-12-22T15:53:34Z</dc:date>
    </item>
    <item>
      <title>Re: How do I script the directory in which this script is located?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-do-i-script-the-directory-in-which-this-script-is-located/m-p/3449241#M708044</link>
      <description>i've always used:&lt;BR /&gt;program="${0:##*/}"&lt;BR /&gt;path="${0:%/*}"&lt;BR /&gt;&lt;BR /&gt;for posix type shells</description>
      <pubDate>Wed, 22 Dec 2004 18:39:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-do-i-script-the-directory-in-which-this-script-is-located/m-p/3449241#M708044</guid>
      <dc:creator>c_51</dc:creator>
      <dc:date>2004-12-22T18:39:54Z</dc:date>
    </item>
    <item>
      <title>Re: How do I script the directory in which this script is located?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-do-i-script-the-directory-in-which-this-script-is-located/m-p/3449242#M708045</link>
      <description>I guess i left out a bit,&lt;BR /&gt;&lt;BR /&gt;path="${0:%/*}"&lt;BR /&gt;#&lt;BR /&gt;# find where I am, absolute path to this directory&lt;BR /&gt;#&lt;BR /&gt;oldDir=$(pwd)&lt;BR /&gt;cd $path&lt;BR /&gt;mydir=$(pwd)&lt;BR /&gt;cd $oldDir&lt;BR /&gt;</description>
      <pubDate>Wed, 22 Dec 2004 19:51:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-do-i-script-the-directory-in-which-this-script-is-located/m-p/3449242#M708045</guid>
      <dc:creator>c_51</dc:creator>
      <dc:date>2004-12-22T19:51:48Z</dc:date>
    </item>
    <item>
      <title>Re: How do I script the directory in which this script is located?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-do-i-script-the-directory-in-which-this-script-is-located/m-p/3449243#M708046</link>
      <description>This is going to be tricky because $0 is the name used to start the script. The basename will be the name of the script but unless the user uses a full pathname, $0 will report just what was used to start it. It might be: scriptname ./scriptname ../scriptname bin/scriptname, etc. &lt;BR /&gt; &lt;BR /&gt;You'll need to test the dirname results. If it starts with /, then you have a full pathname and you know where it came from. If dirname is empty or contains relative locations, then the location can be determined with the construct:&lt;BR /&gt; &lt;BR /&gt;MYNAME=${0##*/}&lt;BR /&gt;MYDIR=$(dirname $0)&lt;BR /&gt;if [ $(echo $MYDIR | cut -c 1) != / ]&lt;BR /&gt;then&lt;BR /&gt;MYFULLPATH=$(whence ./$MYDIR/$MYNAME)&lt;BR /&gt;else&lt;BR /&gt;MYFULLPATH=$MYDIR/$MYNAME&lt;BR /&gt;fi&lt;BR /&gt;echo $MYFULLPATH&lt;BR /&gt; &lt;BR /&gt;In this snippet of code, we use the shell to perform basename, but use dirname rather than ${0:%/*}. The reason is that if the script is started by the simple name, the shell construct returns the basename rather than . so we use dirname to make sure it is really a valid directory reference.&lt;BR /&gt; &lt;BR /&gt;The way it works is to put ./ in front of whatever dirname is found in $0. Then run the ./DIRNAME/SCRIPTNAME through whence and it returns a useable full pathname. Note that you may see an extra ./ in $MYFULLPATH but it is still a valid directory reference.&lt;BR /&gt; &lt;BR /&gt;This sample has been tested with:&lt;BR /&gt; &lt;BR /&gt;/tmp/myscript&lt;BR /&gt;myscript&lt;BR /&gt;./myscript&lt;BR /&gt;../myscript&lt;BR /&gt;../bin/myscript&lt;BR /&gt;./././myscript&lt;BR /&gt; &lt;BR /&gt;and so on. It should identify the full pathname of the script regardless of how it was invoked.</description>
      <pubDate>Wed, 22 Dec 2004 23:23:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-do-i-script-the-directory-in-which-this-script-is-located/m-p/3449243#M708046</guid>
      <dc:creator>Bill Hassell</dc:creator>
      <dc:date>2004-12-22T23:23:12Z</dc:date>
    </item>
    <item>
      <title>Re: How do I script the directory in which this script is located?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-do-i-script-the-directory-in-which-this-script-is-located/m-p/3449244#M708047</link>
      <description>Had that problem some time ago and just digged this from one of my scripts:&lt;BR /&gt; &lt;BR /&gt;MYNAME=$(cd $(dirname $0); pwd -P)/${0##*/}&lt;BR /&gt; &lt;BR /&gt;Best regards...&lt;BR /&gt;Dietmar.</description>
      <pubDate>Thu, 23 Dec 2004 07:17:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-do-i-script-the-directory-in-which-this-script-is-located/m-p/3449244#M708047</guid>
      <dc:creator>Dietmar Konermann</dc:creator>
      <dc:date>2004-12-23T07:17:43Z</dc:date>
    </item>
    <item>
      <title>Re: How do I script the directory in which this script is located?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-do-i-script-the-directory-in-which-this-script-is-located/m-p/3449245#M708048</link>
      <description>Oh, just saw that you asked for the dierectory...that would be:&lt;BR /&gt; &lt;BR /&gt;MYDIR=$(cd $(dirname $0); pwd -P)</description>
      <pubDate>Thu, 23 Dec 2004 07:19:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-do-i-script-the-directory-in-which-this-script-is-located/m-p/3449245#M708048</guid>
      <dc:creator>Dietmar Konermann</dc:creator>
      <dc:date>2004-12-23T07:19:52Z</dc:date>
    </item>
  </channel>
</rss>

