Hey I want to add a command to my system. I am not using any package-format or anything. I just want to install a script that I wrote.

I know of some ways to do that:

  • add my script into whatever is the first thing in $PATH
  • add a custom path to $PATH (in /etc/profile.d/ or /etc/environment) and put the script into the custom path
  • add my script into /usr/bin or /usr/local/bin

I remember reading that profile.d/ doesn’t get picked up by all shells and that /etc/environment (which exists but is empty on my system) shouldn’t be used.

What should I do to ensure that my command will be available everywhere on any gnu/linux or bsd system?

EDIT: I should clarify that I am asking this only out of curiosity. I just like knowing how this stuff works. The script was just an example (I thought this would make it easier to understand, lol). I am interested in knowing a way to install a command without any chance of that command later not being found by other programs. I find many different answers to this and they all seem a little muddy, like “doing x should usually work”. I want to know the solution that always works

  • flubba86@lemmy.world
    link
    fedilink
    arrow-up
    10
    ·
    10 months ago

    That’s a good point about it going last in your PATH. Malicious applications running as non-root can still install payloads to ~/.local/bin and hijack common system functions.

    • ZeroEcks@lemmy.ml
      link
      fedilink
      arrow-up
      6
      ·
      10 months ago

      Yeah, consider a script named Sudo that reads as follows

      sudo virus-payload && sudo "$@”

          • Alex@feddit.ro
            link
            fedilink
            arrow-up
            2
            ·
            10 months ago

            The first one only runs the actual command after the virus payload finishes, and only if it succeeds. The second one runs both almost at the same time

      • IAm_A_Complete_Idiot@sh.itjust.works
        link
        fedilink
        arrow-up
        4
        ·
        10 months ago

        Only for it’s child processes, e.g. call a bash script with a modified PATH. Still problematic though.

        …I suppose they could also modify your .bashrc equivalent.