<?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 Expand a path passed to a script in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/expand-a-path-passed-to-a-script/m-p/4953669#M103576</link>
    <description>I'm working in HP-UX 11.11 using the ksh shell.  Does anyone know how I can expand a path that has been passed as a parameter to a script?&lt;BR /&gt;&lt;BR /&gt;For example, if the current directory is "/database/app" and the user passes "../bin", I need to expand it to "/database/bin".  Or if the current directory is "/database/app" and the user passes "../bin/myfile.txt" I need it to expand to "/database/bin/myfile.txt".&lt;BR /&gt;&lt;BR /&gt;I've come up with a way to brute force the result but I have to believe there's an easier way.  I've included my brute force method in an attachment.&lt;BR /&gt;&lt;BR /&gt;Any help would be appreciated.</description>
    <pubDate>Thu, 19 Jan 2006 14:47:27 GMT</pubDate>
    <dc:creator>Steve Tesch</dc:creator>
    <dc:date>2006-01-19T14:47:27Z</dc:date>
    <item>
      <title>Expand a path passed to a script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/expand-a-path-passed-to-a-script/m-p/4953669#M103576</link>
      <description>I'm working in HP-UX 11.11 using the ksh shell.  Does anyone know how I can expand a path that has been passed as a parameter to a script?&lt;BR /&gt;&lt;BR /&gt;For example, if the current directory is "/database/app" and the user passes "../bin", I need to expand it to "/database/bin".  Or if the current directory is "/database/app" and the user passes "../bin/myfile.txt" I need it to expand to "/database/bin/myfile.txt".&lt;BR /&gt;&lt;BR /&gt;I've come up with a way to brute force the result but I have to believe there's an easier way.  I've included my brute force method in an attachment.&lt;BR /&gt;&lt;BR /&gt;Any help would be appreciated.</description>
      <pubDate>Thu, 19 Jan 2006 14:47:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/expand-a-path-passed-to-a-script/m-p/4953669#M103576</guid>
      <dc:creator>Steve Tesch</dc:creator>
      <dc:date>2006-01-19T14:47:27Z</dc:date>
    </item>
    <item>
      <title>Re: Expand a path passed to a script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/expand-a-path-passed-to-a-script/m-p/4953670#M103577</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;If you need to use expanded path in the script, use, if the path is the first parameter:&lt;BR /&gt;PATH=$PATH:$PWD/$1&lt;BR /&gt;If you want to expand path for your interactive shell, run&lt;BR /&gt;&lt;BR /&gt;. script dirname &lt;BR /&gt;&lt;BR /&gt;after the shell prompt.&lt;BR /&gt;The script should contain the same string&lt;BR /&gt;&lt;BR /&gt;HTH</description>
      <pubDate>Thu, 19 Jan 2006 14:55:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/expand-a-path-passed-to-a-script/m-p/4953670#M103577</guid>
      <dc:creator>Victor Fridyev</dc:creator>
      <dc:date>2006-01-19T14:55:10Z</dc:date>
    </item>
    <item>
      <title>Re: Expand a path passed to a script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/expand-a-path-passed-to-a-script/m-p/4953671#M103578</link>
      <description>Hi Steve:&lt;BR /&gt;&lt;BR /&gt;I don't understand whell what you need to do, because if are in /database/app and you use the ../bin or replace by /database/bin, you have the same results. I don't see the difference.&lt;BR /&gt;</description>
      <pubDate>Thu, 19 Jan 2006 15:03:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/expand-a-path-passed-to-a-script/m-p/4953671#M103578</guid>
      <dc:creator>Ivan Ferreira</dc:creator>
      <dc:date>2006-01-19T15:03:42Z</dc:date>
    </item>
    <item>
      <title>Re: Expand a path passed to a script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/expand-a-path-passed-to-a-script/m-p/4953672#M103579</link>
      <description>Victor,&lt;BR /&gt;Ivan,&lt;BR /&gt;&lt;BR /&gt;Apparently my original explanation was not clear.  When I stated that I need to be able to expand a path, I did not mean PATH, I was simply referring to any combination of typed directories the user may pass to a script, which is why I included examples.&lt;BR /&gt;&lt;BR /&gt;As to the reason this is required; while you are correct that the examples I gave are equivalent within the shell, the relative paths have no meaning to another user viewing the results unless they know where the script was run from in the first place.  This particular script can be run from anywhere on the system and the results have to indicate absolute paths in order to make any sense.&lt;BR /&gt;&lt;BR /&gt;If that were the only issue, simply reporting the starting directory would reoslve the problem.  However, absolute paths are a must when the results have to be sortable in a spreadsheet by path.  Attempting to sort relative paths and make any sense of them is impossible.&lt;BR /&gt;&lt;BR /&gt;I hope this helps clarify what I'm looking for.&lt;BR /&gt;&lt;BR /&gt;Steve</description>
      <pubDate>Thu, 19 Jan 2006 15:26:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/expand-a-path-passed-to-a-script/m-p/4953672#M103579</guid>
      <dc:creator>Steve Tesch</dc:creator>
      <dc:date>2006-01-19T15:26:22Z</dc:date>
    </item>
    <item>
      <title>Re: Expand a path passed to a script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/expand-a-path-passed-to-a-script/m-p/4953673#M103580</link>
      <description>What if you simply use:&lt;BR /&gt;&lt;BR /&gt;APP_PATH=/database/app&lt;BR /&gt;&lt;BR /&gt;Then, in your script, always use:&lt;BR /&gt;&lt;BR /&gt;$APP_PATH/$1&lt;BR /&gt;&lt;BR /&gt;So, if APP_PATH is /database/app, and the user passes ../bin, doest matter where he is, he will go to&lt;BR /&gt;&lt;BR /&gt;/database/app/../bin -&amp;gt; /database/bin</description>
      <pubDate>Thu, 19 Jan 2006 15:47:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/expand-a-path-passed-to-a-script/m-p/4953673#M103580</guid>
      <dc:creator>Ivan Ferreira</dc:creator>
      <dc:date>2006-01-19T15:47:14Z</dc:date>
    </item>
    <item>
      <title>Re: Expand a path passed to a script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/expand-a-path-passed-to-a-script/m-p/4953674#M103581</link>
      <description>Hi Steve:&lt;BR /&gt;&lt;BR /&gt;# cat getpath&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;pwd&lt;BR /&gt;echo ${1}&lt;BR /&gt;WHERE=`perl -le 'use Cwd qw(realpath);print realpath $ARGV[0];' $1`&lt;BR /&gt;echo ${WHERE}&lt;BR /&gt;&lt;BR /&gt;For example:&lt;BR /&gt;&lt;BR /&gt;# cd /var/tmp/dummydir &amp;amp;&amp;amp; ./getpath ../bin&lt;BR /&gt;/var/tmp/dummydir&lt;BR /&gt;../bin&lt;BR /&gt;/var/tmp/bin&lt;BR /&gt;&lt;BR /&gt;Does that help?  This is based on the realpath() C library function.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Thu, 19 Jan 2006 15:58:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/expand-a-path-passed-to-a-script/m-p/4953674#M103581</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-01-19T15:58:51Z</dc:date>
    </item>
    <item>
      <title>Re: Expand a path passed to a script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/expand-a-path-passed-to-a-script/m-p/4953675#M103582</link>
      <description>Victor,&lt;BR /&gt;&lt;BR /&gt;Again, the issue isn't manipulating directories within the shell, it's being able to report the absolute path, even if the user specified a relative one.&lt;BR /&gt;&lt;BR /&gt;The answer is straight-forward if the user actually passes a directory but if they pass a filename, it gets much trickier as you can see from the brute force method I uploaded.&lt;BR /&gt;&lt;BR /&gt;Steve</description>
      <pubDate>Thu, 19 Jan 2006 15:59:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/expand-a-path-passed-to-a-script/m-p/4953675#M103582</guid>
      <dc:creator>Steve Tesch</dc:creator>
      <dc:date>2006-01-19T15:59:48Z</dc:date>
    </item>
    <item>
      <title>Re: Expand a path passed to a script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/expand-a-path-passed-to-a-script/m-p/4953676#M103583</link>
      <description>James,&lt;BR /&gt;&lt;BR /&gt;Your answer looks like it's on the right track but I get the following error when i attempt to run it:&lt;BR /&gt;&lt;BR /&gt;Can't locate Cwd.pm in @INC (@INC contains: /opt/perl5/lib/5.00502/PA-RISC1.1 /opt/perl5/lib/5.00502 /opt/perl5/lib/site_perl/5.005/PA-RISC1.1 /opt/perl5/lib/site_perl/5.005 .) at -e line 1.&lt;BR /&gt;BEGIN failed--compilation aborted at -e line 1.&lt;BR /&gt;&lt;BR /&gt;Any thoughts?&lt;BR /&gt;&lt;BR /&gt;Steve</description>
      <pubDate>Thu, 19 Jan 2006 16:05:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/expand-a-path-passed-to-a-script/m-p/4953676#M103583</guid>
      <dc:creator>Steve Tesch</dc:creator>
      <dc:date>2006-01-19T16:05:31Z</dc:date>
    </item>
    <item>
      <title>Re: Expand a path passed to a script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/expand-a-path-passed-to-a-script/m-p/4953677#M103584</link>
      <description>Hi,&lt;BR /&gt;Just one simple idea.&lt;BR /&gt;Is the commands "basename" and "dirname" of any help ?&lt;BR /&gt;&lt;BR /&gt;dirname return the directory part of a path and, basename the filename.</description>
      <pubDate>Thu, 19 Jan 2006 16:08:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/expand-a-path-passed-to-a-script/m-p/4953677#M103584</guid>
      <dc:creator>Leif Halvarsson_2</dc:creator>
      <dc:date>2006-01-19T16:08:27Z</dc:date>
    </item>
    <item>
      <title>Re: Expand a path passed to a script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/expand-a-path-passed-to-a-script/m-p/4953678#M103585</link>
      <description>Hi Steve:&lt;BR /&gt;&lt;BR /&gt;It appears that the 'Cwd' module required isn't in your rather old version of perl.&lt;BR /&gt;&lt;BR /&gt;You could download the module from CPAN:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://search.cpan.org/~kwilliams/PathTools-3.15/Cwd.pm" target="_blank"&gt;http://search.cpan.org/~kwilliams/PathTools-3.15/Cwd.pm&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;...or better, yet, upgrade your version of perl:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://h20293.www2.hp.com/portal/swdepot/displayProductInfo.do?productNumber=PERL" target="_blank"&gt;http://h20293.www2.hp.com/portal/swdepot/displayProductInfo.do?productNumber=PERL&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Thu, 19 Jan 2006 16:11:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/expand-a-path-passed-to-a-script/m-p/4953678#M103585</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-01-19T16:11:31Z</dc:date>
    </item>
    <item>
      <title>Re: Expand a path passed to a script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/expand-a-path-passed-to-a-script/m-p/4953679#M103586</link>
      <description>First, my apologies, I addressed a previous reply to Victor when it should have been addressed to Ivan.&lt;BR /&gt;&lt;BR /&gt;Leif - Thanks for the input but dirname and basename do not expand relative paths.  They were one of my first attempts.&lt;BR /&gt;&lt;BR /&gt;James - I appricate the quick response.  I'll look into updating my perl and let you know how it turns out.&lt;BR /&gt;&lt;BR /&gt;Thanks to all,&lt;BR /&gt;&lt;BR /&gt;Steve</description>
      <pubDate>Thu, 19 Jan 2006 16:16:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/expand-a-path-passed-to-a-script/m-p/4953679#M103586</guid>
      <dc:creator>Steve Tesch</dc:creator>
      <dc:date>2006-01-19T16:16:37Z</dc:date>
    </item>
    <item>
      <title>Re: Expand a path passed to a script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/expand-a-path-passed-to-a-script/m-p/4953680#M103587</link>
      <description>Still trying:&lt;BR /&gt;&lt;BR /&gt;APP_PATH=/database/app&lt;BR /&gt;FULLPATH=`cd $APP_PATH/$1; pwd`&lt;BR /&gt;echo $FULLPATH</description>
      <pubDate>Thu, 19 Jan 2006 16:17:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/expand-a-path-passed-to-a-script/m-p/4953680#M103587</guid>
      <dc:creator>Ivan Ferreira</dc:creator>
      <dc:date>2006-01-19T16:17:06Z</dc:date>
    </item>
    <item>
      <title>Re: Expand a path passed to a script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/expand-a-path-passed-to-a-script/m-p/4953681#M103588</link>
      <description>And going, and going...&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;APP_PATH=/var/adm/syslog&lt;BR /&gt;RELATIVE=`echo $1 |grep "^\."|wc -l`&lt;BR /&gt;&lt;BR /&gt;# If the arg starts with dot, then is  a relative path, else just use the specified path&lt;BR /&gt;if [ $RELATIVE -gt 1 ]; then&lt;BR /&gt;  REALPATH=`cd $APP_PATH/$1;pwd`&lt;BR /&gt;fi&lt;BR /&gt;</description>
      <pubDate>Thu, 19 Jan 2006 16:20:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/expand-a-path-passed-to-a-script/m-p/4953681#M103588</guid>
      <dc:creator>Ivan Ferreira</dc:creator>
      <dc:date>2006-01-19T16:20:03Z</dc:date>
    </item>
    <item>
      <title>Re: Expand a path passed to a script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/expand-a-path-passed-to-a-script/m-p/4953682#M103589</link>
      <description>Hi Steve:&lt;BR /&gt;&lt;BR /&gt;The perl update is quick and simple and so, so worthwhile.  Perl 5.8.x has incorporated lots of good things into its core.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Thu, 19 Jan 2006 16:21:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/expand-a-path-passed-to-a-script/m-p/4953682#M103589</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-01-19T16:21:09Z</dc:date>
    </item>
    <item>
      <title>Re: Expand a path passed to a script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/expand-a-path-passed-to-a-script/m-p/4953683#M103590</link>
      <description>Ivan,&lt;BR /&gt;&lt;BR /&gt;Your solution works if the user passes a directory, and is very similar to the method I uploaded.  However if they are passing a filename, it gets an error.&lt;BR /&gt;&lt;BR /&gt;I need a solution for both possibilities.&lt;BR /&gt;&lt;BR /&gt;Thanks for the continued effort.&lt;BR /&gt;&lt;BR /&gt;Steve&lt;BR /&gt;</description>
      <pubDate>Thu, 19 Jan 2006 16:22:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/expand-a-path-passed-to-a-script/m-p/4953683#M103590</guid>
      <dc:creator>Steve Tesch</dc:creator>
      <dc:date>2006-01-19T16:22:26Z</dc:date>
    </item>
    <item>
      <title>Re: Expand a path passed to a script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/expand-a-path-passed-to-a-script/m-p/4953684#M103591</link>
      <description>Sorry, I did not see your previous reply addressed to victor (me) about the file.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 19 Jan 2006 16:29:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/expand-a-path-passed-to-a-script/m-p/4953684#M103591</guid>
      <dc:creator>Ivan Ferreira</dc:creator>
      <dc:date>2006-01-19T16:29:55Z</dc:date>
    </item>
    <item>
      <title>Re: Expand a path passed to a script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/expand-a-path-passed-to-a-script/m-p/4953685#M103592</link>
      <description>Ivan,&lt;BR /&gt;&lt;BR /&gt;Your new solution works in most cases but not all.  If you pass it a sub-directory of the current directory, it will return the current directory, instead of the full path to the sub-directory.&lt;BR /&gt;&lt;BR /&gt;Your first solution did not have this problem.  Also, this solution still can't handle a filename.&lt;BR /&gt;&lt;BR /&gt;Thanks again,&lt;BR /&gt;&lt;BR /&gt;Steve</description>
      <pubDate>Thu, 19 Jan 2006 16:31:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/expand-a-path-passed-to-a-script/m-p/4953685#M103592</guid>
      <dc:creator>Steve Tesch</dc:creator>
      <dc:date>2006-01-19T16:31:01Z</dc:date>
    </item>
    <item>
      <title>Re: Expand a path passed to a script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/expand-a-path-passed-to-a-script/m-p/4953686#M103593</link>
      <description>CUR=/abc/def&lt;BR /&gt;DIR=$(dirname ../xyz/abc.txt)&lt;BR /&gt;FILE=$(basename ../xyz/abc.txt)&lt;BR /&gt;&lt;BR /&gt;cd $DIR&lt;BR /&gt;ABSOLUTE=$(pwd)&lt;BR /&gt;&lt;BR /&gt;FULL_PATH=${ABSOLUTE}/${FILE}&lt;BR /&gt;&lt;BR /&gt;it should work also with an absolute path or a filename only&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 19 Jan 2006 16:34:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/expand-a-path-passed-to-a-script/m-p/4953686#M103593</guid>
      <dc:creator>Leif Halvarsson_2</dc:creator>
      <dc:date>2006-01-19T16:34:54Z</dc:date>
    </item>
    <item>
      <title>Re: Expand a path passed to a script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/expand-a-path-passed-to-a-script/m-p/4953687#M103594</link>
      <description>You could compile the following c program that takes a path as its only argument and returns the real path. (Even compiles with the brain dead supplied cc compiler).&lt;BR /&gt; &lt;BR /&gt;#include &lt;STDLIB.H&gt;&lt;BR /&gt;main(argc,argv,envp)&lt;BR /&gt;int argc;&lt;BR /&gt;char *argv[],*envp[];&lt;BR /&gt;{&lt;BR /&gt; char realp[255];&lt;BR /&gt; (void)realpath(argv[1],realp);&lt;BR /&gt; printf("%s\n",realp);&lt;BR /&gt; exit(0);&lt;BR /&gt;}&lt;BR /&gt; &lt;BR /&gt;HTH&lt;BR /&gt; &lt;BR /&gt;-- Rod Hills&lt;/STDLIB.H&gt;</description>
      <pubDate>Thu, 19 Jan 2006 16:36:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/expand-a-path-passed-to-a-script/m-p/4953687#M103594</guid>
      <dc:creator>Rodney Hills</dc:creator>
      <dc:date>2006-01-19T16:36:22Z</dc:date>
    </item>
    <item>
      <title>Re: Expand a path passed to a script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/expand-a-path-passed-to-a-script/m-p/4953688#M103595</link>
      <description>Leif,&lt;BR /&gt;&lt;BR /&gt;Very close!  However, if the user passes a path or filename that is already in absolute format (i.e. /home), your solution doubles the initial forward slash (i.e. //home).  If they pass the root directory, it returns three forward slashes (i.e. ///).&lt;BR /&gt;&lt;BR /&gt;Thanks for the effort,&lt;BR /&gt;&lt;BR /&gt;Steve</description>
      <pubDate>Thu, 19 Jan 2006 16:45:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/expand-a-path-passed-to-a-script/m-p/4953688#M103595</guid>
      <dc:creator>Steve Tesch</dc:creator>
      <dc:date>2006-01-19T16:45:17Z</dc:date>
    </item>
  </channel>
</rss>

