Score:1

Opening a piece of software from anywhere

br flag

I have a compiled program in a certain folder that I would like to access from anywhere without needing the write ./path/to/file/each/time/app_name. For example, the app executable is installed in this ./path/to/file/each/time/app_name path, and I would like to be able to open it by writing app_name in the command line, and nothing more than that. How could I do that?

Score:1
in flag

Create a script (as root) called /usr/local/bin/app_name and put this inside it:

#!/bin/bash

/path/to/file/app_name $@

Then make the script executable:

sudo chmod +x /usr/local/bin/app_name
vanadium avatar
cn flag
Better also explain why and how that works. You may also want to complete the answer by adding another option, i.e. to place a symlink to the executable in `/usr/local/bin`. In addition, it is worthwhile mentioning the option to use ~/bin or ~/.local/bin if only the current user needs access - in that case, no root access is needed.
Kristopher Ives avatar
in flag
`~/.bin` and such are not in `$PATH` by default so that's a deeper rabbit hole. There are other problems with symlinks. This solution works everywhere regardless of those problems and also allows you to do more flexible things like add default arguments or run more complex composite commands.
vanadium avatar
cn flag
.bin is automatically included in the path if it exist on Ubuntu, so no rabitt hole there. There is more rabitt holes in trying to do everything as root. With symlinks, there will be no more problems than with your approach. If an app requires you to start in a specific folder or set an environment before, then indeed a wrapper script is the way to go.
Kristopher Ives avatar
in flag
Nope. The default path for 20.04 LTS is `/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin`
vanadium avatar
cn flag
You must have a different linux version then, or you are using a different shell.
Kristopher Ives avatar
in flag
Nope. These are default `$PATH` values, see https://askubuntu.com/questions/386629/what-are-the-default-path-values
Zanna avatar
kr flag
`~/bin` is added to PATH if and only if it exists (as vanadium says). You can find the code that adds it in `~/.profile`
Score:0
jp flag

Create an alias for your program in the .bashrc file.

nano ~/.bashrc

At the end of the file type the line:

alias app_name=/path/to/file/each/time/app_name

Then save (CTRL+O then Enter) and exit (CTRL+X).

You will be able to use the alias in new Terminal windows you open.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.