Skip to content

Instantly share code, notes, and snippets.

@Georgy5
Created July 29, 2024 13:37
Show Gist options
  • Save Georgy5/72a97ca62e30e8accfc2eb20396d0a1a to your computer and use it in GitHub Desktop.
Save Georgy5/72a97ca62e30e8accfc2eb20396d0a1a to your computer and use it in GitHub Desktop.
Resolving full path to a shell script
# Full path to this script
# two different ways to get the same full path
SCRIPT_DIR=$(dirname $(readlink -f $0))
REALPATH=$(dirname $(realpath $0))
echo "This script is located in: $SCRIPT_DIR"
echo "This script realpath is located in: $REALPATH"
# example use case:
# sudo cp "$SCRIPT_DIR/nginx.conf" /etc/nginx/conf.d/rails_app.conf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment