0
  1. I would like to know why in order to get current directory from within a script we need to use solution such as:DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" taken from here.
    Instead of something like:
    DIR=$("pwd")

  2. Once I have current directory of current script, and I want to calculate its parent's parent parent directory path, how do I do that? In terminal its simply cd ../../../, how this can be caluclated on DIR and assigned to a new variable?

  3. What is the difference in bash assignment between NUM:=1 and NUM=1

Cheers

JavaSa
  • 5,813
  • 16
  • 71
  • 121
  • You should ask 3 questions as 3 separate questions. Which answer will you flag as correct if there are 3 different answers, one for each question? – choroba Nov 15 '17 at 19:36
  • The link you give literally answers question 1 does it not? – Sam Redway Nov 15 '17 at 19:43

1 Answers1

2
  1. That's not the current directory, but the directory where the script is located. Other similar solutions are readlink -f "${0%/*}" etc.

  2. You can add the double dots to the DIR:

    great_grand_parent=$DIR/../../..
    

    Call readlink or do the magic with cd to get rid of the double dots.

  3. NUM:=1 is not an assignment at all.

choroba
  • 231,213
  • 25
  • 204
  • 289