New answers tagged

2

The standard path to /Users/[current user] is tilde ~ So the path to /Users/{$USERNAME}/CloudSync/Projects/Hello World/ for any user is ~/CloudSync/Projects/Hello World/


2

The answers here do not always contain best practices, so if you just want the directory echoed on the screen (even when it contains spaces): #!/bin/bash echo "My Script is being run from here: $(dirname "$0")" If you want it into a variable and want . expanded to the full path, you need GNU Readlink first so: Install homebrew Install GNU CoreUtils: brew ...


3

See the answers on Get the source directory of a Bash script from within the script itself. The accepted one recommends #!/bin/bash DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" but reading all the answers gives a lot of alternatives (and insights into how shells work).


Top 50 recent answers are included