<?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: Finding absolute path of 'sourced' shell script in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/finding-absolute-path-of-sourced-shell-script/m-p/4481317#M680385</link>
    <description>Actually, "which" and "whereis" are deprecated because they do not match what the shell will do. The correct (and only useful) command is whence and whence -v. whence -v is so useful that it is always aliased to the "type" command. Things like $PWD are useless because users can change the contents and you never want to use a relative pathname (a sourced script always starts with: /)&lt;BR /&gt; &lt;BR /&gt;To see why which and whereis are not useful:&lt;BR /&gt; &lt;BR /&gt;which for&lt;BR /&gt;whereis for&lt;BR /&gt;whence -v for&lt;BR /&gt; &lt;BR /&gt;The only correct answer is whence -v for. This is even more telling:&lt;BR /&gt; &lt;BR /&gt;which type&lt;BR /&gt;whereis type&lt;BR /&gt;whence -v type&lt;BR /&gt; &lt;BR /&gt;which and whereis both report that /usr/bin/type is the location of the command but your script will *not* run /usr/bin/type. Instead, it will run the alias. This is critically important for sourced scripts and other commands that a user may have aliased or have $PATH set to unsafe locations.&lt;BR /&gt; &lt;BR /&gt;I will explictly set PATH and unset all aliases in my critical scripts to prevent accidents (or hacks):&lt;BR /&gt; &lt;BR /&gt;export PATH=/usr/bin:/usr/sbin:/usr/contrib/bin&lt;BR /&gt;unalias -a&lt;BR /&gt; &lt;BR /&gt;</description>
    <pubDate>Wed, 19 Aug 2009 02:29:00 GMT</pubDate>
    <dc:creator>Bill Hassell</dc:creator>
    <dc:date>2009-08-19T02:29:00Z</dc:date>
    <item>
      <title>Finding absolute path of 'sourced' shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/finding-absolute-path-of-sourced-shell-script/m-p/4481313#M680381</link>
      <description>We use a ksh script which is sourced from different directories. This script sets project paths and other environment variables based on the absolute path of the script.&lt;BR /&gt;The issue is that the path of this script is not fixed as it changes based on the directory it is checked out.&lt;BR /&gt;If it is sourced from a different directory the $PWD or `dirname` displayed is that of the directory which sources it and 'not' the directory of the 'sourced script'.&lt;BR /&gt;&lt;BR /&gt;Can someone please suggest a solution for this ? &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 18 Aug 2009 08:53:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/finding-absolute-path-of-sourced-shell-script/m-p/4481313#M680381</guid>
      <dc:creator>vinay naik</dc:creator>
      <dc:date>2009-08-18T08:53:16Z</dc:date>
    </item>
    <item>
      <title>Re: Finding absolute path of 'sourced' shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/finding-absolute-path-of-sourced-shell-script/m-p/4481314#M680382</link>
      <description>Vinay,&lt;BR /&gt;&lt;BR /&gt;You could use the 'which' command prior to executing. This would tell you which, pardon the pun, sourced script you are executing.&lt;BR /&gt;&lt;BR /&gt;HTH&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Berd</description>
      <pubDate>Tue, 18 Aug 2009 08:57:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/finding-absolute-path-of-sourced-shell-script/m-p/4481314#M680382</guid>
      <dc:creator>Berd</dc:creator>
      <dc:date>2009-08-18T08:57:41Z</dc:date>
    </item>
    <item>
      <title>Re: Finding absolute path of 'sourced' shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/finding-absolute-path-of-sourced-shell-script/m-p/4481315#M680383</link>
      <description>Since a sourced file isn't a script, I don't think there is any way to get the path except have the caller set a variable.&lt;BR /&gt;&lt;BR /&gt;Sourced files do undergo $PATH lookup, not sure if that is helpful.</description>
      <pubDate>Tue, 18 Aug 2009 09:24:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/finding-absolute-path-of-sourced-shell-script/m-p/4481315#M680383</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2009-08-18T09:24:32Z</dc:date>
    </item>
    <item>
      <title>Re: Finding absolute path of 'sourced' shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/finding-absolute-path-of-sourced-shell-script/m-p/4481316#M680384</link>
      <description>to put a which OR find to source every time script run will have negative effect as a big delay.&lt;BR /&gt;&lt;BR /&gt;why do not you consider a copy of source to known directory on your local ?</description>
      <pubDate>Tue, 18 Aug 2009 10:05:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/finding-absolute-path-of-sourced-shell-script/m-p/4481316#M680384</guid>
      <dc:creator>Hakki Aydin Ucar</dc:creator>
      <dc:date>2009-08-18T10:05:31Z</dc:date>
    </item>
    <item>
      <title>Re: Finding absolute path of 'sourced' shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/finding-absolute-path-of-sourced-shell-script/m-p/4481317#M680385</link>
      <description>Actually, "which" and "whereis" are deprecated because they do not match what the shell will do. The correct (and only useful) command is whence and whence -v. whence -v is so useful that it is always aliased to the "type" command. Things like $PWD are useless because users can change the contents and you never want to use a relative pathname (a sourced script always starts with: /)&lt;BR /&gt; &lt;BR /&gt;To see why which and whereis are not useful:&lt;BR /&gt; &lt;BR /&gt;which for&lt;BR /&gt;whereis for&lt;BR /&gt;whence -v for&lt;BR /&gt; &lt;BR /&gt;The only correct answer is whence -v for. This is even more telling:&lt;BR /&gt; &lt;BR /&gt;which type&lt;BR /&gt;whereis type&lt;BR /&gt;whence -v type&lt;BR /&gt; &lt;BR /&gt;which and whereis both report that /usr/bin/type is the location of the command but your script will *not* run /usr/bin/type. Instead, it will run the alias. This is critically important for sourced scripts and other commands that a user may have aliased or have $PATH set to unsafe locations.&lt;BR /&gt; &lt;BR /&gt;I will explictly set PATH and unset all aliases in my critical scripts to prevent accidents (or hacks):&lt;BR /&gt; &lt;BR /&gt;export PATH=/usr/bin:/usr/sbin:/usr/contrib/bin&lt;BR /&gt;unalias -a&lt;BR /&gt; &lt;BR /&gt;</description>
      <pubDate>Wed, 19 Aug 2009 02:29:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/finding-absolute-path-of-sourced-shell-script/m-p/4481317#M680385</guid>
      <dc:creator>Bill Hassell</dc:creator>
      <dc:date>2009-08-19T02:29:00Z</dc:date>
    </item>
    <item>
      <title>Re: Finding absolute path of 'sourced' shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/finding-absolute-path-of-sourced-shell-script/m-p/4481318#M680386</link>
      <description>&amp;gt;Bill: "which" and "whereis" are deprecated because they do not match what the shell will do. &lt;BR /&gt;&lt;BR /&gt;I always think of them as scummy C shell commands, not to be used for a real shell, unless you have a bad path setting.</description>
      <pubDate>Wed, 19 Aug 2009 07:20:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/finding-absolute-path-of-sourced-shell-script/m-p/4481318#M680386</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2009-08-19T07:20:08Z</dc:date>
    </item>
    <item>
      <title>Re: Finding absolute path of 'sourced' shell script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/finding-absolute-path-of-sourced-shell-script/m-p/4481319#M680387</link>
      <description>Bill / Dennis - I will never again use which, whence is the way !&lt;BR /&gt;&lt;BR /&gt;Berd</description>
      <pubDate>Wed, 19 Aug 2009 09:22:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/finding-absolute-path-of-sourced-shell-script/m-p/4481319#M680387</guid>
      <dc:creator>Berd</dc:creator>
      <dc:date>2009-08-19T09:22:54Z</dc:date>
    </item>
  </channel>
</rss>

