I have a bin/ under $HOME. This contains some augmented versions of common commands. Hence, I don't want these commands to be used by scripts, but only to be used in interactive use.

Is the best I can do to add

for f in ~/bin/*
    alias "$(basename $f)"="$f"

to my ~/.bash_profile? Or is there another solution?

  • PATH gets inherited from the interactive shell, so aliases or functions seem like the best option. Though you may want to put aliases in .bashrc to get them loaded in all interactive shells, not just login shells. – ilkkachu Apr 28 '17 at 8:35

You also can add the lines as follows to your .bashrc, which only sets the PATH if you are in a interactive shell.

if [ "$PS1" ]
    export PATH=~/bin:$PATH
  • PATH will already be exported, so there isn't really any need to export it again. – tripleee Apr 27 '17 at 18:22
  • This will also set the path for all programs started by that shell. – Gilles Apr 27 '17 at 22:17

You could use environment modules to manually enable (load) a module setting the desired path

module load homebin

Where homebin module would look like

prepend-path PATH ~/bin



It depends on which shell and (unfortunately) which system you are using. Bash, for example, uses different startup files depending on whether it is used as an interactive or non-interactive shell, as explained in the bash manual.

In principle you should be able to add export PATH=$HOME/bin:$PATH to your ~/.bashrc file, which then will be executed only for interactive non-login shells. In practice some systems are configured such that they read ~/.bashrc also for non-interactive shells.

Related questions:

  • That wouldn't help, since the setting would also affect all programs started by the interactive instance of bash. – Gilles Apr 27 '17 at 22:17
  • @Gilles You are right of course; my bad. I assume this would work if one would mark PATH as no longer to be exported, but that would have terrible side effects. Setting up aliases sounds like a good solution then. Perhaps one could do that in the interactive-only startup file .bashrc? – user8153 Apr 27 '17 at 23:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.