System bindir

A typical location for programs that are accessible system-wide on most Unix-like systems is /usr/local/bin, and this directory is included in the $PATH of every user. If you want hello to be available system-wide, and you have permission to write to /usr/local/bin, you might put it there, using su or sudo to get root permissions first:

bash$ sudo -s
Password:
bash# mv hello /usr/local/bin

Note that for the last command line, we use bash# instead of bash$, to denote a shell that is running as the system administrative root user.

If we're able to do this, we should be able to call the hello program from anywhere on the system and as any user, just with the word hello:

bash$ hello Hello, bashuser! bash$ sudo -s Password: bash# ...

Get Bash Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.