Skip to main content
added 11 characters in body
Source Link
Serious Angel
  • 2.5k
  • 5
  • 29
  • 38

You can use $BASH_SOURCE:

#!/usr/bin/env bash

scriptdir="$( dirname -- "$BASH_SOURCE""$BASH_SOURCE"; )";

Note that you need to use #!/bin/bash and not #!/bin/sh since it's a Bash extension.

You can use $BASH_SOURCE:

#!/bin/bash

scriptdir="$(dirname -- "$BASH_SOURCE")";

Note that you need to use #!/bin/bash and not #!/bin/sh since it's a Bash extension.

You can use $BASH_SOURCE:

#!/usr/bin/env bash

scriptdir="$( dirname -- "$BASH_SOURCE"; )";

Note that you need to use #!/bin/bash and not #!/bin/sh since it's a Bash extension.

added 6 characters in body
Source Link
Serious Angel
  • 2.5k
  • 5
  • 29
  • 38

You can use $BASH_SOURCE:

#!/bin/bash

scriptdir=$scriptdir="$(dirname -- "$BASH_SOURCE")";

Note that you need to use #!/bin/bash and not #!/bin/sh since it's a Bash extension.

You can use $BASH_SOURCE:

#!/bin/bash

scriptdir=$(dirname "$BASH_SOURCE")

Note that you need to use #!/bin/bash and not #!/bin/sh since it's a Bash extension.

You can use $BASH_SOURCE:

#!/bin/bash

scriptdir="$(dirname -- "$BASH_SOURCE")";

Note that you need to use #!/bin/bash and not #!/bin/sh since it's a Bash extension.

added 1 character in body
Source Link
Dave Jarvis
  • 31.3k
  • 43
  • 186
  • 325

You can use $BASH_SOURCE:

#!/bin/bash

scriptdir=`dirnamescriptdir=$(dirname "$BASH_SOURCE"`"$BASH_SOURCE")

Note that you need to use #!/bin/bash and not #!/bin/sh since it's a Bash extension.

You can use $BASH_SOURCE:

#!/bin/bash

scriptdir=`dirname "$BASH_SOURCE"`

Note that you need to use #!/bin/bash and not #!/bin/sh since it's a Bash extension.

You can use $BASH_SOURCE:

#!/bin/bash

scriptdir=$(dirname "$BASH_SOURCE")

Note that you need to use #!/bin/bash and not #!/bin/sh since it's a Bash extension.

edited for readability
Source Link
the Tin Man
  • 160.9k
  • 44
  • 222
  • 308
Loading
Added extra quotes as per Charles Duffys comment
Source Link
Mr Shark
  • 26.5k
  • 5
  • 32
  • 38
Loading
Post Made Community Wiki
Source Link
Mr Shark
  • 26.5k
  • 5
  • 32
  • 38
Loading