I want to let every file know the path of the root of a project. For example let’s consider this the root: /home/username/.config/project. If I have a folder in the project and every file in the folder has a line like ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" (gets the absolute path of the parent directory) whenever I move the folder to another location I may have to change that line for every file in the folder.

Is there a better option to let every file know the path of the project root?

I think using paths relative to ${BASH_SOURCE[0]} is alright.

Otherwise, using ${XDG_CONFIG_HOME:-$HOME/.config} is pretty standard.

Ask specific questions about how to code something in sh, bash, zsh, etc

General bash discussion on lemmy.ml

Create Post From:
lemmy.ml

  • 0 users online
  • 2 users / day
  • 2 users / week
  • 2 users / month
  • 5 users / 6 months
  • 17 subscribers
  • 9 Posts
  • 17 Comments
  • Modlog