Skip to content

Instantly share code, notes, and snippets.

@andmax
Created January 14, 2021 19:22
Show Gist options
  • Save andmax/44c6dbb1603a7ccccde467268ddfe120 to your computer and use it in GitHub Desktop.
Save andmax/44c6dbb1603a7ccccde467268ddfe120 to your computer and use it in GitHub Desktop.
Replace the last character of the last line of a file with sed
1. The problem is to add a new entry to the PATH
2. environment variable for all users system wide
3. for both logged-in (interactive) and non-logged-in
4. (non-interactive) shells using the /etc/environment
5. (the /etc/profile.d scripts are only applied to logged-in shells)
6. which is not a bash script rather a list of one variable set
7. (without appending) per line and I want to replace the already
8. existing PATH in the last line (there is only one line)
9. by removing the last character (a double quote) with a
10. colon (:) and then appending the new entry to PATH
11. that is OpenMPI binaries path:
su -
echo $(sed '$ s/.$/:/' /etc/environment)/usr/local/openmpi/bin/\" >> /etc/environment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment