Quick tip: how to add hdbsql to a $PATH on MacOS

I was following that new tutorials mission Use Clients to Query an SAP HANA Database published this week by Daniel Van Leeuwen and I finally installed hdbsql on my MacOS. I used hdbsql on Linux and on Windows in the past, but — for whatever reason — never on Mac.

Once I was done with the standard installation I got all SAP HANA clients in the default (as of now, for the version 2.4) directory /Applications/sap/hdbclient/.

The next step should be to add this directory to the $PATH environment variable. Ok, the installation comes with the helpful, yet little known, bash script called hdbclienv.sh. Once you execute…

source /Applications/sap/hdbclient/hdbclienv.sh

… it will set environment variable HDB_CLIENT_HOME and will add it to the $PATH in your session.

But I still need to type that path, if I want to run it… So, the question remains how do I add this directory with SAP HANA Clients to my system’s $PATH?

I’ve done this hundred times on Windows, where there is the central location to edit it for a current user or for all users. But what is that central location for MacOS?

Obviously, because I am using bash right now, I can simply add this to my bash profile. But as a developer advocate I want to think not only about my preferences, but as well about other preferences that developers in our SAP HANA community might have. As well, I know /etc/profile is the system-wide profile, but it can be modified or overwritten by another MacOS upgrade.

After a bit of a research I finally found what I was looking for: the special location /etc/paths.d where applications or users can add a file containing the list of directories that should be added to the $PATH system-wide.

Let’s try it!

Only user root can write to /etc/paths.d, so I need to do something like…

sudo sh -c 'echo "/Applications/sap/hdbclient" >> /etc/paths.d/sap'

… and to open another session to check it working.

which hdbsql which hdbclienv.sh source hdbclienv.sh echo $HDB_CLIENT_HOME hdbsql


I hope those of you using MacOS will find it useful too 🙂

Stay healthy and have a good weekend,
-Vitaliy (aka @Sygyzmundovych)