S
S
Sergei E.2018-09-28 22:26:25
linux
Sergei E., 2018-09-28 22:26:25

How to check if a folder is system/user?

Greetings!
There is such a tricky task, you need to check whether the directory is from the $XDG_DATA_DIRSuser or system. Depending on the result, the config will be saved in ~/.configor in /var/lib. It will be used in such a simple construction:

_is_system_dir() {
  local dir="$1"

  if [ "$dir" == something ]; then
     return 0
  fi

  return 1
}

Requirements:
  • pure bash or commands from coreutils
  • human-readable expression
  • work in cases where $HOMEit differs from/home
  • do not break when run as root

Path examples:
# пользовательские
/home/user/.local/share/
/home/user/.local/share/flatpak/exports/share/
/var/home/user/.local/share/

# системные
/var/lib/flatpak/exports/share/
/usr/share/ubuntu
/usr/local/share/
/usr/share/

I hope for fresh ideas, I know how to solve it in a dumb way.
UPD1: In general, I realized that I will not get what I ask for here and I have to think for myself.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
pfg21, 2018-09-29
@SmartFinn

the standard is registered in the Filesystem Hierarchy Standard , but in each operating system there are certain deviations from the standard

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question