Skip to content

Instantly share code, notes, and snippets.

@andmax
Created January 14, 2021 19:14
Show Gist options
  • Save andmax/0596cce359fa56af9070b3b7a92b437a to your computer and use it in GitHub Desktop.
Save andmax/0596cce359fa56af9070b3b7a92b437a to your computer and use it in GitHub Desktop.
If file exists in bash to fix path with sed
1. The problem is with a file created by someone
2. (docker or nimbix internal configuration or ...)
3. in profile.d that sets PATH without appending to it
4. removing the previous content of PATH that can be set
5. by /etc/environment (a global system wide way of setting
6. environment variables such as PATH) the fix tests if the
7. bug file exists in a bash script to then replace its
8. content with a sed replacing substring "PATH=" by "PATH+=\:".
9. The result is:
if [ -f "/etc/profile.d/00-container-environment.sh" ]; then
sudo sed -i 's/PATH=/PATH+=\\:/' /etc/profile.d/00-container-environment.sh
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment