Project

General

Profile

Bug #3219

MANPATH setting is fragile

Added by Jellby empty about 1 year ago. Updated about 1 month ago.

Status:
Resolved
Priority:
Normal
Assignee:
-
Category:
-
Target version:
-
Affected version - extra info:
Affected version:
Difficulty:
simple
Close

Description

In Ubuntu 18.04, with TeXLive, I have:

$ echo $MANPATH
:/usr/local/texlive/2019/texmf-dist/doc/man

After sourcing GMXRC.bash:

$ . /usr/local/gromacs/bin/GMXRC.bash
$ echo $MANPATH
/usr/local/gromacs/share/man:/usr/local/texlive/2019/texmf-dist/doc/man
$ man bash
No manual entry for bash
See 'man 7 undocumented' for help when manual pages are not available.

It seems GMXRC.bash assumes that MANPATH will be empty or end with a colon, but in my case it starts with a colon.

See #2628 and https://mailman-1.sys.kth.se/pipermail/gromacs.org_gmx-users/2007-January/025471.html, and man manpath.

Associated revisions

Revision 51b2fdb3 (diff)
Added by Andrey Alekseenko about 1 month ago

Rework handling of PATH-like variables in GMXRC.bash/zsh

Old version was not robust to various kinds of trailing colons, as
exerienced in, e.g., #3219.

To make it all safer, a single function, that removes the
old path and adds the new one to the beginning, is introduced.

Tested with:
- GNU bash 4.4.20
- GNU bash 5.0.17
- zsh 5.8
- dash 0.5.8

```
$ replace_in_path ":" "/new" "/old"
/new:
$ replace_in_path "" "/new" "/old"
/new
$ replace_in_path "/old" "/new" "/old"
/new
$ replace_in_path "/old:" "/new" "/old"
/new:
$ replace_in_path "/old:/other" "/new" "/old"
/new:/other
$ replace_in_path ":/other" "/new" "/old"
/new::/other
$ replace_in_path "/other:" "/new" "/old"
/new:/other:
$ replace_in_path "/other:/old" "/new" "/old"
/new:/other
```

Full test:

```
$ bash -c 'MANPATH=''; . scripts/GMXRC.bash; echo $MANPATH;'
/usr/local/gromacs/share/man
$ bash -c 'MANPATH=':'; . scripts/GMXRC.bash; echo $MANPATH;'
/usr/local/gromacs/share/man:
$ bash -c 'MANPATH='/abc'; . scripts/GMXRC.bash; echo $MANPATH;'
/usr/local/gromacs/share/man:/abc
$ bash -c 'MANPATH='/abc:'; . scripts/GMXRC.bash; echo $MANPATH;'
/usr/local/gromacs/share/man:/abc:

$ bash -c 'MANPATH=':'; . scripts/GMXRC.bash; . scripts/GMXRC.bash; . scripts/GMXRC.bash; echo $MANPATH;'
/usr/local/gromacs/share/man:
$ bash -c 'MANPATH=''; . scripts/GMXRC.bash; . scripts/GMXRC.bash; . scripts/GMXRC.bash; echo $MANPATH;'
/usr/local/gromacs/share/man
$ bash -c 'MANPATH='/abc'; . scripts/GMXRC.bash; . scripts/GMXRC.bash; . scripts/GMXRC.bash; echo $MANPATH;'
/usr/local/gromacs/share/man:/abc
$ bash -c 'MANPATH='/abc:'; . scripts/GMXRC.bash; . scripts/GMXRC.bash; . scripts/GMXRC.bash; echo $MANPATH;'
/usr/local/gromacs/share/man:/abc:
```

Closes #2628, #3219

Revision 7f00d40f (diff)
Added by Andrey Alekseenko about 1 month ago

Rework handling of PATH-like variables in GMXRC.bash/zsh

Old version was not robust to various kinds of trailing colons, as
experienced in, e.g., #3219.

To make it all safer, a single function, that removes the
old path and adds the new one to the beginning, is introduced.

Tested with:
- GNU bash 4.4.20
- GNU bash 5.0.17
- zsh 5.8
- dash 0.5.8

```
$ replace_in_path ":" "/new" "/old"
/new:
$ replace_in_path "" "/new" "/old"
/new
$ replace_in_path "/old" "/new" "/old"
/new
$ replace_in_path "/old:" "/new" "/old"
/new:
$ replace_in_path "/old:/other" "/new" "/old"
/new:/other
$ replace_in_path ":/other" "/new" "/old"
/new::/other
$ replace_in_path "/other:" "/new" "/old"
/new:/other:
$ replace_in_path "/other:/old" "/new" "/old"
/new:/other
```

Full test:

```
$ bash -c 'MANPATH=''; . scripts/GMXRC.bash; echo $MANPATH;'
/usr/local/gromacs/share/man
$ bash -c 'MANPATH=':'; . scripts/GMXRC.bash; echo $MANPATH;'
/usr/local/gromacs/share/man:
$ bash -c 'MANPATH='/abc'; . scripts/GMXRC.bash; echo $MANPATH;'
/usr/local/gromacs/share/man:/abc
$ bash -c 'MANPATH='/abc:'; . scripts/GMXRC.bash; echo $MANPATH;'
/usr/local/gromacs/share/man:/abc:

$ bash -c 'MANPATH=':'; . scripts/GMXRC.bash; . scripts/GMXRC.bash; . scripts/GMXRC.bash; echo $MANPATH;'
/usr/local/gromacs/share/man:
$ bash -c 'MANPATH=''; . scripts/GMXRC.bash; . scripts/GMXRC.bash; . scripts/GMXRC.bash; echo $MANPATH;'
/usr/local/gromacs/share/man
$ bash -c 'MANPATH='/abc'; . scripts/GMXRC.bash; . scripts/GMXRC.bash; . scripts/GMXRC.bash; echo $MANPATH;'
/usr/local/gromacs/share/man:/abc
$ bash -c 'MANPATH='/abc:'; . scripts/GMXRC.bash; . scripts/GMXRC.bash; . scripts/GMXRC.bash; echo $MANPATH;'
/usr/local/gromacs/share/man:/abc:
```

Closes #2628, #3219

History

#1 Updated by Anonymous about 1 month ago

  • Status changed from New to Resolved

#2 Updated by Anonymous about 1 month ago

Also available in: Atom PDF