sh current_dir

Assuming you’re using bash

#!/bin/bash

current_dir=$(pwd)
script_dir=$(dirname $0)

echo $current_dir
echo $script_dir
This script, when ran, should print the directory that you’re in, and then the directory the script is in, for example, when calling it from / (the script is in /home/mez/), it outputs

/
/home/mez
Remember, when assigning variables from the output of a command, wrap the command in $( and ) – or you’ll not get the desired output. `

Tags: , , ,