Bash rules or practices

Home Forums Community Bash rules or practices

This topic contains 1 reply, has 2 voices, and was last updated by  Vince 4 years, 3 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #511

    Mr Leslie
    Participant

    The /etc/skel/.bash_profile before was Fedora 20
    # Get the aliases and functions
    if [ -f ~/.bashrc ]; then
    . ~/.bashrc
    fi

    # User specific environment and startup programs
    if [ -d $HOME/bin ] ; then
    PATH=$HOME/bin:$PATH
    fi

    What the skeleton (user’s .bash_profile) did was to add the users ~/bin directory to the fron of the path, if the bin directory existed. At the front so that user software executable having an identical name to another in the path, should take priority over other the other.

    Fedora20 took the approach that it did not matter, all one needs is to have ~/bin and ~/.local/bin as the tail end of the path statement, even if the directories did not exist, and all would be ok.

    That is not quite right. Searching the path causes problems if the directories do not exist. However, the result was quiet, because the two directories were last in the $PATH.

    Fedora20 did not place the ~/bin first in the PATH, which was the practice.

    The following is the Fedora 20 /etc/skel/.bash_profile.
    The /etc/skel/.bash_profile before was Fedora 20
    # Get the aliases and functions
    if [ -f ~/.bashrc ]; then
    . ~/.bashrc
    fi

    # User specific environment and startup programs
    PATH=$PATH:$HOME/.local/bin:$HOME/bin

    The revised version which I implemented follows:

    # .bash_profile

    # Get the aliases and functions
    if [ -f ~/.bashrc ]; then
    . ~/.bashrc
    fi

    # User specific environment and startup programs
    if [ -d $HOME/bin ] ; then
    PATH=$HOME/bin:$PATH
    fi

    if [ -d $HOME/.local/bin ]; tnen
    PATH=$PATH:$HOME/.local/bin
    fi

    export PATH

    If neither directory exists, the path will not include $HOME/bin or the $HOME/.local/bin
    and will only add each to the path if each existed.

    What is your opinion

    #512

    Vince
    Keymaster

    Hi again lsatenstein,

    Bit of random one :), firstly I thought you were suggesting that Chapeau’s skeleton .bash_profile was different to Fedora 20’s packaged in the bash package which puzzled me somewhat (it isn’t btw).

    Anyway my personal opinion is that I prefer binaries to be in the standard locations (and /opt for standalone binaries) so having binary paths within userspace directories isn’t really a thing for me nor does it seem good practice but I’m sure there’s use-cases that doesn’t apply to me.

    One could argue that it is potentially unsafe to have a userspace binary overriding a system binary as theorhetically, unprivileged software or a script could create or alter a binary for malicious purposes in ~/bin without the user’s knowledge. I suppose SELinux helps with addressing such software behaviour (so long as the user doesn’t disable SELinux which plenty do).

    I don’t think there’s much benefit of having standalone native software in your home directory unless you reinstall your OS often, have a dedicated volume for /home and a need run standalone binaries with full access perms.
    If one prefers to run self-compiled software then the common thing would be to install using the install script which pops them in the right places with the right perms anyway or stick em in the /opt or /usr/local directories, not run them from ~/bin.

    Do you use these?

    • This reply was modified 4 years, 11 months ago by  Vince.
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Bash rules or practices’ is closed to new replies.

Comments are closed.