Artificial intelligent assistant

Access installation folder from cli in bash package I am creating a package (weffe) written purely in bash containing an executable and static files the script needs to access. However, I would like this script to be able to be run with local files if the package is cloned with git or if it's installed to `/usr/bin/weffe` with data in the `/usr/share/weffe` folder. If the package is run from the command line, e.g. if `weffe` is run on a terminal, is there any way for the binary to be aware of its own installation directory (in this case `/usr/share/weffe`) by running a command like `whereis` or accessing a shell variable? If this is not possible, what's the best alternative? Some things I have considered are making a Makefile that manually creates a variable for the installation directory during the build process, or checking if the hard-coded `/usr/share/weffe` directory exists before trying to access files from that location. Any help would be appreciated.

Consider locating the `weffe` executable at `/usr/share/weffe/weffe-or-other-name` and then linking to it in the `bin` directory, e.g., `cd /usr/bin; ln -s ../share/weffe/weffe`.

Your script can find its location with the `dirname` command. When its a symlink, the symlink path will be returned. So, if you want to find its "real" path then you may use a combination of `dirname` and `readlink`.


#!/usr/bin/env bash

# Assuming you have soft linked in the bin dir.
# cd /usr/bin; ln -s ../share/weffe/weffe

# /usr/share/weffe/weffe
script_path="$(dirname "$0")"
# GNU readlink requires a -f argument.
# macOS realink does not require -f argument.
script_real_relative_path="$(readlink "$0")"
echo "script path: $script_path"
echo "script real path: $script_real_relative_path"

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy db1562c24c092ff881ac71fd114fac70