2

I have some installation instructions but they use pathmunge which caused me an error in Ubuntu. What is the equivalent syntax to the following script to do the same in Ubuntu?

/etc/profile.d/openssl.sh
pathmunge /usr/local/openssl/bin

I did add pathmunge command to Ubuntu using this answer:

run nano ~/.bashrc && source ~/.bashrc and paste this:

pathmunge () {
        if ! echo $PATH | /bin/egrep -q "(^|:)$1($|:)" ; then
           if [ "$2" = "after" ] ; then
              PATH=$PATH:$1
           else
              PATH=$1:$PATH
           fi
        fi
}

When I login, I get this error:

error loading /etc/profile.d/openssh.sh

muru
  • 197,895
  • 55
  • 485
  • 740
  • @karel I did not get that answer you posted. Can you please provide me clear syntax on how to do the line I posted in Ubunut? I am not a Linux user so not familiar with that. – user9371654 Aug 05 '18 at 03:15
  • For example, the commands at the end of this answer: https://askubuntu.com/questions/1060474/tar-no-such-file-or-directory-error-during-scala-installation/1060476#1060476 prepend a path, which is stored in a variable named $SCALA_HOME, to the PATH variable. – karel Aug 05 '18 at 03:22
  • So is just replacing pathmunge with export is all what it needs? – user9371654 Aug 05 '18 at 03:25
  • 1
    @user9371654 Essentially yes. export PATH=$PATH:/usr/local/openssl/bin – Sergiy Kolodyazhnyy Aug 05 '18 at 03:37
  • 1
    You never normally need to export PATH though, because it is already in the environment (you can think of it as being already exported) (cc @SergiyKolodyazhnyy). It's enough to write PATH=$PATH:/thing/I/want/to/append – Zanna Aug 05 '18 at 16:17

1 Answers1

2

Apparently in RHEL and CentOS, pathmunge is a shell function declared in /etc/profile (source). You can simply add that very same function to your /etc/profile or ~/.bashrc (which needs to be sourced after you add the function).

For simplicity, run nano ~/.bashrc && source ~/.bashrc and paste this:

pathmunge () {
        if ! echo $PATH | /bin/egrep -q "(^|:)$1($|:)" ; then
           if [ "$2" = "after" ] ; then
              PATH=$PATH:$1
           else
              PATH=$1:$PATH
           fi
        fi
}

Save the file after pasting with Ctrl+o (that's lowercase o, not zero), and exit with Ctrl+x. The command will be available for use after that.

Alternatively, you can just add directory to PATH by hand, temporarily as in PATH=$PATH:/usr/local/openssl/bin , or permanently as provided in How to add a directory to the PATH? by modifying /etc/profile (global for all users) or better by modifying ~/.bashrc file if you just need this for your user.

Sergiy Kolodyazhnyy
  • 105,154
  • 20
  • 279
  • 497
  • If I will paste this code you posted for pathmunge, what should I name the file? using what extension? – user9371654 Aug 05 '18 at 03:31
  • @user9371654 Please reread the answer. This is supposed to go into your ~/.bashrc file. Once you paste it there, run source .bashrc. The function will be available for use after that. No need for files or extensions – Sergiy Kolodyazhnyy Aug 05 '18 at 03:34
  • Your answer said just run sudo nano this opens new file. You did not clarify I should edit an exisiting file. – user9371654 Aug 05 '18 at 03:36
  • @user9371654 Ok, I thought that was clear. I can edit that – Sergiy Kolodyazhnyy Aug 05 '18 at 03:38
  • I added the code for pathmunge to ~/.bashrc. I added the script that uses pathmunge. When I start my machine I get error message saying: error found when loading /etc/profile. ~/.bashrc and that it can not find pathmunge. – user9371654 Aug 05 '18 at 03:45
  • can you plz look at my OP edit? I posted the error message. – user9371654 Aug 05 '18 at 03:53
  • @user9371654 OK, after reading the tutorial you linked, the command is apparently required globally not just in ~/.bashrc, although it's entirely unnecessary. Let's just put export PATH=$PATH:/usr/local/openssl/bin into /etc/profile.d/openssl.sh and see if that works. – Sergiy Kolodyazhnyy Aug 05 '18 at 04:26
  • this worked for me. Thanks. If you can update this to the answer please? it will be more complete and will accept it. – user9371654 Aug 05 '18 at 12:02