Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This appears to change your shell's working directory to the directory where the script is stored. This is probably done so that the script can refer to other things in the same directory as itself.</p> <p>I've used a variant of this before, <code>location=$(dirname $0)</code>. This does not change the directory, but rather stores the script's path for later use. <code>dirname $0</code> takes a filename (in this case, $0 or the path where the shell found that file), and <code>echo</code>es the directory that it is stored in. Wrapping a command (or a sequence of commands) in a <code>$()</code> combination causes the <em>output</em> of the command (whatever is printed to the screen by <code>echo</code>, <code>df</code>, <code>cat</code>, etc) to replace that expression using <code>$()</code>. Example: <code>variable=$(echo "test")</code> becomes <code>variable="test"</code></p> <p>As in other programming languages, <code>$()</code> can be nested. An example is: <code>variable=$(echo $(echo "test"))</code> The inner-most expression will print 'test', which will then be substituted as the argument to the outermost <code>echo</code>. The output of this <code>echo</code> will then be substituted as the value to store in <code>variable</code> - the result of the first and second example will be identical. A stupid example. but it works.</p> <p>The only different between <code>$(dirname $(readlink -f $0))</code> and <code>$(dirname $0)</code> that I can see is that the former always returns the <em>absolute path</em>. The latter can return the relative path or the absolute path, depending on where the working directory is in relation to the script.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload