Use "./lib" only works if the following two statements are true

The only way to make sure that the current working directory is set to the application directory is to write a script that changes to "known" directory location. But how are you to know that directory location? You could force your user to store that application in a hard coded location, but that really isn't very guest-like.

You could let your user choose a location and then set an environment variable during registration, but then you have no way of making sure that the application location and the environment variable stay in sync. You could educate your user about the environment variable, but now you have yet one more thing to teach and your users have yet one more thing that could go wrong.

But even if your users were happy with the environment variable, would they be happy with being forced to change directories to the application directory every time the script starts up? And maybe the system is set up so that users can read and execute script files but they are not allowed to go exploring in application directories (e.g. they don't have permission to make the application directory their current working directory)?

So in the main it is just more reliable to locate your application script without relying on cd or the current working directory. The script above avoids this by using some tricks to deduce the fully qualified path to the application. Then it appends a relative path.

The actual relative path will depend on the layout of the application directory. In the script above, the layout is

The relative path is "../lib". Thus in "$fullPathOfScript/../lib", ".." moves up from the script's own directory to its parent directory, i.e. from appdir/bin to appdir. "lib" moves back down again to appdir/lib

Hope that helps, beth


In reply to Re^3: Question: Best practices for packaging scripts by ELISHEVA
in thread Question: Best practices for packaging scripts by jujiro_eb

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.