I wrote a shell script, and I’m trying to automate it’s installation. For that, I have a script that 1.) downloads the script to ~/.local/bin
2.) adds a line to .bashrc
(or config.fish
, etc.). The line for .bashrc
looks like eval "$(myscript init bash)"
.
This causes bash
to throw an error on login – -bash: myscript: command not found
. The issue is that ~/.local/bin
is added to PATH
after .bashrc
has been sourced (through ~/.profile
).
I’m now unsure if I should either move the script to a different location or the eval
statement. Here are a few things that I’ve considered:
- It would work if I moved the
eval
statement to~/.profile
, but is that the right location for such a statement? - The next best place that comes to mind for the script is probably
~/bin
, but that’s also added toPATH
after.bashrc
is sourced. /usr/local/bin
could also be an option, but for that, the user would need to run the install script with sudo, which is not what I want.
What would be the best location for the script and for the eval
statement, for this to work?