Taco Steemers

A personal blog.

Notes on bash

" Bash is the GNU Project's shell—the Bourne Again SHell ."

Script name, directory, present working directory

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
#!/bin/bash

echo "Script name:"
echo "$BASH_SOURCE"
echo "$0"

echo "Directory that contains the currently running script, relative to PWD:"
echo "$(dirname $BASH_SOURCE)"
echo "$(dirname "$0")"
echo "${0%/*}"

echo "Present working directory: $PWD"

Includes the ./ when we call the script like ./my_script , but not when calling as sh my_script .

See this stackoverflow post . See also this stackoverflow post .