K
K
kunjut192020-02-14 23:38:58
macOS
kunjut19, 2020-02-14 23:38:58

How to use the path to the running script as a path to another folder?

Here is the simplest script that I run to specify the path to the database:

--dbpath <path_to_some_folder>/data/db

In this case <path_to_some_folder>, this is the path to the folder where the script is located. But when copying it to another folder, I have to manually change it <path_to_some_folder>to the path to the folder from which I run it. I would like the script to add the path to itself to the path to the database. Namely, like this:

--dbpath <path_to_the_script_folder>/data/db

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DevMan, 2020-02-15
@kunjut19

DIR=`dirname "$(realpath "$0")"`

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question