<?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: absolute path of a script in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/absolute-path-of-a-script/m-p/3267683#M178081</link>
    <description>Claudio,&lt;BR /&gt;Sorry i did not interpreted it properly. Okay now i have one solution for you.&lt;BR /&gt;I tested this on POSIX shell and working fine.&lt;BR /&gt;&lt;BR /&gt;ABSPATH=`find / -name script.sh -print`&lt;BR /&gt;&lt;BR /&gt;Remember i have used back quotes there. But only problem is it will take some time to scan everything. &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Wed, 05 May 2004 02:56:54 GMT</pubDate>
    <dc:creator>Bharat Katkar</dc:creator>
    <dc:date>2004-05-05T02:56:54Z</dc:date>
    <item>
      <title>absolute path of a script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/absolute-path-of-a-script/m-p/3267679#M178077</link>
      <description>hi all.&lt;BR /&gt;&lt;BR /&gt;I have got a question for you:&lt;BR /&gt;&lt;BR /&gt;I need to know, inside a shell script, the absolute full path of the script itself.&lt;BR /&gt;&lt;BR /&gt;example:&lt;BR /&gt;the script is located in /home/user/scripts/script.sh .&lt;BR /&gt;&lt;BR /&gt;I need a way to get the full string "/home/user/scripts/script.sh" in a variable named ABSPATH independently how I run the script:&lt;BR /&gt;&lt;BR /&gt;$ /home/user/scripts/script.sh&lt;BR /&gt;&lt;BR /&gt;or&lt;BR /&gt;&lt;BR /&gt;$ cd /home/user/scripts/&lt;BR /&gt;$ ./script.sh&lt;BR /&gt;&lt;BR /&gt;or&lt;BR /&gt;&lt;BR /&gt;$ cd /home/user/scripts/otherdir&lt;BR /&gt;$ ../script.sh&lt;BR /&gt;&lt;BR /&gt;HP-UX 11.&lt;BR /&gt;&lt;BR /&gt;thanks all,&lt;BR /&gt;Claudio</description>
      <pubDate>Wed, 05 May 2004 02:44:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/absolute-path-of-a-script/m-p/3267679#M178077</guid>
      <dc:creator>Claudio Cilloni</dc:creator>
      <dc:date>2004-05-05T02:44:39Z</dc:date>
    </item>
    <item>
      <title>Re: absolute path of a script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/absolute-path-of-a-script/m-p/3267680#M178078</link>
      <description>what about adding this variable in your script:&lt;BR /&gt;&lt;BR /&gt;VAR1=$PWD&lt;BR /&gt;&lt;BR /&gt;Don't know this is what you are looking for!!!&lt;BR /&gt;</description>
      <pubDate>Wed, 05 May 2004 02:47:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/absolute-path-of-a-script/m-p/3267680#M178078</guid>
      <dc:creator>Bharat Katkar</dc:creator>
      <dc:date>2004-05-05T02:47:54Z</dc:date>
    </item>
    <item>
      <title>Re: absolute path of a script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/absolute-path-of-a-script/m-p/3267681#M178079</link>
      <description>Inside the script ?&lt;BR /&gt;&lt;BR /&gt;ABSOLUTE_PATH_OFCURRENT_SCRIPT=`which $0`&lt;BR /&gt;&lt;BR /&gt;Regds,&lt;BR /&gt;&lt;BR /&gt;Kapil</description>
      <pubDate>Wed, 05 May 2004 02:52:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/absolute-path-of-a-script/m-p/3267681#M178079</guid>
      <dc:creator>KapilRaj</dc:creator>
      <dc:date>2004-05-05T02:52:48Z</dc:date>
    </item>
    <item>
      <title>Re: absolute path of a script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/absolute-path-of-a-script/m-p/3267682#M178080</link>
      <description>Or a batter one would be &lt;BR /&gt;&lt;BR /&gt;SCRIPT=`basename $0`&lt;BR /&gt;VAR=`which $SCRIPT`&lt;BR /&gt;&lt;BR /&gt;Regds,&lt;BR /&gt;&lt;BR /&gt;Kaps</description>
      <pubDate>Wed, 05 May 2004 02:55:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/absolute-path-of-a-script/m-p/3267682#M178080</guid>
      <dc:creator>KapilRaj</dc:creator>
      <dc:date>2004-05-05T02:55:20Z</dc:date>
    </item>
    <item>
      <title>Re: absolute path of a script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/absolute-path-of-a-script/m-p/3267683#M178081</link>
      <description>Claudio,&lt;BR /&gt;Sorry i did not interpreted it properly. Okay now i have one solution for you.&lt;BR /&gt;I tested this on POSIX shell and working fine.&lt;BR /&gt;&lt;BR /&gt;ABSPATH=`find / -name script.sh -print`&lt;BR /&gt;&lt;BR /&gt;Remember i have used back quotes there. But only problem is it will take some time to scan everything. &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 05 May 2004 02:56:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/absolute-path-of-a-script/m-p/3267683#M178081</guid>
      <dc:creator>Bharat Katkar</dc:creator>
      <dc:date>2004-05-05T02:56:54Z</dc:date>
    </item>
    <item>
      <title>Re: absolute path of a script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/absolute-path-of-a-script/m-p/3267684#M178082</link>
      <description>Bharat,&lt;BR /&gt;&lt;BR /&gt;Sorry to interrupt you but obv it will help u as a Sysadmin. Your method would list all such script's present in his system&lt;BR /&gt;&lt;BR /&gt;i.e.&lt;BR /&gt;$HOME/script/script as well as &lt;BR /&gt;/tmp/script&lt;BR /&gt;which is not what he needs ....&lt;BR /&gt;&lt;BR /&gt;What he wants to get is the path of the script which he is currently running. &lt;BR /&gt;&lt;BR /&gt;From his statements we can find that the script is available in his PATH variable and by doing a "whence" or "which" you can locate his script's absolute path.&lt;BR /&gt;&lt;BR /&gt;Do not misunderstand me , I just wanted to make it clear to you , after all we r friends in here ... Good time :)&lt;BR /&gt;&lt;BR /&gt;Regds,&lt;BR /&gt;&lt;BR /&gt;Kaps</description>
      <pubDate>Wed, 05 May 2004 03:08:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/absolute-path-of-a-script/m-p/3267684#M178082</guid>
      <dc:creator>KapilRaj</dc:creator>
      <dc:date>2004-05-05T03:08:25Z</dc:date>
    </item>
    <item>
      <title>Re: absolute path of a script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/absolute-path-of-a-script/m-p/3267685#M178083</link>
      <description>$0 doesn't give you the absolute path to the script.  It only gives the name it was called as.  So, if you called it as "./script", that will be $0.&lt;BR /&gt; &lt;BR /&gt;I think you migth try "which $0" though this isn't guaranteed to be correct either.</description>
      <pubDate>Wed, 05 May 2004 03:13:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/absolute-path-of-a-script/m-p/3267685#M178083</guid>
      <dc:creator>Mark Grant</dc:creator>
      <dc:date>2004-05-05T03:13:19Z</dc:date>
    </item>
    <item>
      <title>Re: absolute path of a script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/absolute-path-of-a-script/m-p/3267686#M178084</link>
      <description>sorry, but the $PWD and the which command give me the relative path of&lt;BR /&gt;my script.&lt;BR /&gt;&lt;BR /&gt;the 'find' solution of Bharat works, but the full tree scan made by the find&lt;BR /&gt;command is too heavy for my needs. thanks anyway.&lt;BR /&gt;&lt;BR /&gt;there is a way (or a command) to intelligently join the values of the&lt;BR /&gt;variables $PWD and $0? I think this could be the solution.&lt;BR /&gt;&lt;BR /&gt;thanks again for your help.&lt;BR /&gt;&lt;BR /&gt;Claudio</description>
      <pubDate>Wed, 05 May 2004 03:18:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/absolute-path-of-a-script/m-p/3267686#M178084</guid>
      <dc:creator>Claudio Cilloni</dc:creator>
      <dc:date>2004-05-05T03:18:30Z</dc:date>
    </item>
    <item>
      <title>Re: absolute path of a script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/absolute-path-of-a-script/m-p/3267687#M178085</link>
      <description>Thanks Kapil,&lt;BR /&gt;You are obsulotely right... See my objective is to learn more and more with people like U and there are very few one's who really interrupt and spend some time to make things clearer. Thanks a lot YAAR.&lt;BR /&gt;And one more thing kapil, do not tell anybody but since you called me friend let me tell that i am bit .. in scripting. :))))&lt;BR /&gt;&lt;BR /&gt;WIth regards,&lt;BR /&gt;Bharat&lt;BR /&gt;</description>
      <pubDate>Wed, 05 May 2004 03:20:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/absolute-path-of-a-script/m-p/3267687#M178085</guid>
      <dc:creator>Bharat Katkar</dc:creator>
      <dc:date>2004-05-05T03:20:55Z</dc:date>
    </item>
    <item>
      <title>Re: absolute path of a script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/absolute-path-of-a-script/m-p/3267688#M178086</link>
      <description>I am surprised to see PWD worked for you !! pwd will show you the path where u r executing it from !&lt;BR /&gt;&lt;BR /&gt;In ksh "which" works for me .. You may also try with "whence"&lt;BR /&gt;&lt;BR /&gt;i.e.&lt;BR /&gt;&lt;BR /&gt;SCR=`basename $0`        # Does this work for u&lt;BR /&gt;whence $SCR&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Regds,&lt;BR /&gt;&lt;BR /&gt;Kaps</description>
      <pubDate>Wed, 05 May 2004 03:33:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/absolute-path-of-a-script/m-p/3267688#M178086</guid>
      <dc:creator>KapilRaj</dc:creator>
      <dc:date>2004-05-05T03:33:35Z</dc:date>
    </item>
    <item>
      <title>Re: absolute path of a script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/absolute-path-of-a-script/m-p/3267689#M178087</link>
      <description>whence $0 seems to work:&lt;BR /&gt;&lt;BR /&gt;$ cd /home/user/scripts/otherdir&lt;BR /&gt;$ ../script.sh&lt;BR /&gt;&lt;BR /&gt;inside the script.sh whence $0 gives /home/user/script/otherdir/../script.sh&lt;BR /&gt;&lt;BR /&gt;this isn't exactly what I'm looking for, but could be enough. Thanks Kapil.&lt;BR /&gt;&lt;BR /&gt;Ciao!&lt;BR /&gt;Claudio</description>
      <pubDate>Wed, 05 May 2004 04:04:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/absolute-path-of-a-script/m-p/3267689#M178087</guid>
      <dc:creator>Claudio Cilloni</dc:creator>
      <dc:date>2004-05-05T04:04:01Z</dc:date>
    </item>
    <item>
      <title>Re: absolute path of a script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/absolute-path-of-a-script/m-p/3267690#M178088</link>
      <description>In ksh this should give you exactly what you want:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/ksh&lt;BR /&gt;&lt;BR /&gt;cd $(dirname $0)&lt;BR /&gt;myScript=$(echo "$PWD/$(basename $0)" | sed 's!//!/!')&lt;BR /&gt;cd - 2&amp;gt;/dev/null&lt;BR /&gt;&lt;BR /&gt;echo "My script is $myScript"&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;The little bit of sed is just there to cover the case where your script is in the root directory.</description>
      <pubDate>Wed, 05 May 2004 19:01:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/absolute-path-of-a-script/m-p/3267690#M178088</guid>
      <dc:creator>Duncan Galbraith</dc:creator>
      <dc:date>2004-05-05T19:01:55Z</dc:date>
    </item>
    <item>
      <title>Re: absolute path of a script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/absolute-path-of-a-script/m-p/3267691#M178089</link>
      <description>I know of no DEFINITE way to do this.&lt;BR /&gt;&lt;BR /&gt;whence will ONLY work if the directory the script resides in is in your PATH environment variable.&lt;BR /&gt;&lt;BR /&gt;If the script you are executing will only reside in a single directory why not just manually code the directory into a variable?&lt;BR /&gt;&lt;BR /&gt;DIR=/path/to/script.sh</description>
      <pubDate>Wed, 05 May 2004 19:24:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/absolute-path-of-a-script/m-p/3267691#M178089</guid>
      <dc:creator>Patrick Wallek</dc:creator>
      <dc:date>2004-05-05T19:24:46Z</dc:date>
    </item>
    <item>
      <title>Re: absolute path of a script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/absolute-path-of-a-script/m-p/3267692#M178090</link>
      <description>mcClaudio,&lt;BR /&gt;&lt;BR /&gt;nice problem. I don't now an easy solution yet. &lt;BR /&gt;&lt;BR /&gt;As you may know, $0 is the name 'as the script is called'.&lt;BR /&gt;Examples are:&lt;BR /&gt;1. /home/user/scripts/script.sh&lt;BR /&gt;2. ../../scripts/script.sh&lt;BR /&gt;3. ./script.sh&lt;BR /&gt;4. ./scripts/script.sh&lt;BR /&gt;5. $SCRIPTS/script.sh&lt;BR /&gt;&lt;BR /&gt;1 is easy, just $0.&lt;BR /&gt;2 - 4 give paths relative to the current directory ($PWD) (at the time the script is called).&lt;BR /&gt;5 may be an absolute or relative path, depending on $SCRIPTS, and will not be discussed further, since the shell will expand the variable $SCRIPTS before execution.&lt;BR /&gt;&lt;BR /&gt;After this analysis, I discover how clever Duncan solves the problem of the relative paths by using 'cd $(dirname $0)'. This eliminates the relative path 'things' (. and ..) from the strings. He prevents editing problems like: how do I change '/home/user/b/../scripts/script.sh' into '/home/user/scripts/script.sh'.&lt;BR /&gt;&lt;BR /&gt;I would use his solution.&lt;BR /&gt;&lt;BR /&gt;JP&lt;BR /&gt;</description>
      <pubDate>Thu, 06 May 2004 01:10:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/absolute-path-of-a-script/m-p/3267692#M178090</guid>
      <dc:creator>Jeroen Peereboom</dc:creator>
      <dc:date>2004-05-06T01:10:19Z</dc:date>
    </item>
    <item>
      <title>Re: absolute path of a script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/absolute-path-of-a-script/m-p/3267693#M178091</link>
      <description>How about setting variable as such?&lt;BR /&gt;&lt;BR /&gt;FILENAME=${0##*/} #script name&lt;BR /&gt;DIRNAME=${0%/*}   #calling path name&lt;BR /&gt;ABSPATH=`pwd`     #absolute path  &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 06 May 2004 07:39:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/absolute-path-of-a-script/m-p/3267693#M178091</guid>
      <dc:creator>David Nardi</dc:creator>
      <dc:date>2004-05-06T07:39:21Z</dc:date>
    </item>
    <item>
      <title>Re: absolute path of a script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/absolute-path-of-a-script/m-p/3267694#M178092</link>
      <description>What do you need the path for?  You question may be easier to answer if you tell us that.&lt;BR /&gt;&lt;BR /&gt;Any way of finding it my end up finding another file/script by the same name. So my thought was that you could "hardcode" it in the script. But that is probably not what you want.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Trond</description>
      <pubDate>Thu, 06 May 2004 07:56:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/absolute-path-of-a-script/m-p/3267694#M178092</guid>
      <dc:creator>Trond Haugen</dc:creator>
      <dc:date>2004-05-06T07:56:55Z</dc:date>
    </item>
    <item>
      <title>Re: absolute path of a script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/absolute-path-of-a-script/m-p/3267695#M178093</link>
      <description>This seems to work&lt;BR /&gt;&lt;BR /&gt;DIR=`pwd`&lt;BR /&gt;cd `dirname $0`&lt;BR /&gt;ABSPATH=`pwd`&lt;BR /&gt;cd $DIR&lt;BR /&gt;unset DIR&lt;BR /&gt;&lt;BR /&gt;Marcel&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 06 May 2004 08:57:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/absolute-path-of-a-script/m-p/3267695#M178093</guid>
      <dc:creator>Marcel Kuiper</dc:creator>
      <dc:date>2004-05-06T08:57:06Z</dc:date>
    </item>
    <item>
      <title>Re: absolute path of a script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/absolute-path-of-a-script/m-p/3267696#M178094</link>
      <description>I'm writing a set of scripts to do some DBA activities on various Oracle&lt;BR /&gt;instances, and I want the script read the ORACLE_SID value from the&lt;BR /&gt;name of the path into it resides. So I can copy these scripts under the base&lt;BR /&gt;directory of each instance and they know, without adding parameters or hardcoded&lt;BR /&gt;variables, the ORACLE_SID to use.&lt;BR /&gt;I want to be able to run these scripts with the full path (for example&lt;BR /&gt;scheduled via cron) and by hand without worring about the path.&lt;BR /&gt;It is good for some colleagues thinking that a script that is located under the&lt;BR /&gt;instance's base directory work on that instance.&lt;BR /&gt;&lt;BR /&gt;Marcel's idea seems the final solution I need. thanks!&lt;BR /&gt;&lt;BR /&gt;Ciao&lt;BR /&gt;Claudio</description>
      <pubDate>Thu, 06 May 2004 10:19:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/absolute-path-of-a-script/m-p/3267696#M178094</guid>
      <dc:creator>Claudio Cilloni</dc:creator>
      <dc:date>2004-05-06T10:19:22Z</dc:date>
    </item>
    <item>
      <title>Re: absolute path of a script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/absolute-path-of-a-script/m-p/3267697#M178095</link>
      <description>Well then maybe /etc/oratab might be a useful thing.  Something like the following.&lt;BR /&gt; &lt;BR /&gt;If $0 contains a path i.e not ./&amp;lt;script&amp;gt; or just &amp;lt;script&amp;gt; then get the part of the path before the script name and look it up in /etc/oratab and get the oracle SID.  If the $0  is one of the two mentioned above then simply use `pwd`, get the last bit of the path returned and look that up in /etc/oratab.&lt;BR /&gt; &lt;BR /&gt;Of course, I might not of understood the question properly.  That happens frequently.</description>
      <pubDate>Thu, 06 May 2004 10:25:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/absolute-path-of-a-script/m-p/3267697#M178095</guid>
      <dc:creator>Mark Grant</dc:creator>
      <dc:date>2004-05-06T10:25:03Z</dc:date>
    </item>
    <item>
      <title>Re: absolute path of a script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/absolute-path-of-a-script/m-p/3267698#M178096</link>
      <description>Having copies of the script in different directories sounds like a pain if you have to modify them all.&lt;BR /&gt;&lt;BR /&gt;Why not add the ORACLE_SID as a parameter to the script?  When you run the script you do it like:&lt;BR /&gt;&lt;BR /&gt;# /path/to/script.sh oracle_sid&lt;BR /&gt;&lt;BR /&gt;If you don't specify a SID, you generate an error.&lt;BR /&gt;&lt;BR /&gt;That would make a whole lot more sense to me.</description>
      <pubDate>Thu, 06 May 2004 10:46:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/absolute-path-of-a-script/m-p/3267698#M178096</guid>
      <dc:creator>Patrick Wallek</dc:creator>
      <dc:date>2004-05-06T10:46:47Z</dc:date>
    </item>
  </channel>
</rss>

