help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Getting the default post-initialisation PATH value at runtime


From: Hu Jialun
Subject: Getting the default post-initialisation PATH value at runtime
Date: Thu, 31 Mar 2022 20:58:38 +0800
User-agent: Evolution 3.44.0

Hello,

I came across this scenerio today: after accidentally setting PATH to
something incorrect, I wanted to revert it to its default when bash
started but was unable to find the default value. Of course it is
possible to open another shell alongside and copy paste, but it just
does not feel the right way.

There seems to be no internal variable or builtin that would allow me
to query this default value. Some distributions seems to have PATH set
again in things like /etc/bash.bashrc, which would make this as easy as
another source, but it is not the case for mine, where bash relies on
the inherited environment or the hardcoded default in
DEFAULT_PATH_VALUE at configure time.

The best I can get for now is

export $(ps wwe -o cmd= $(ps -o ppid= $$) | grep -o '\bPATH=[^ ]*\b')

which is inelegant and can be inaccurate, for example when the parent
does not have PATH set by default.

I wonder if there is any better way to query what the value of PATH
immediately after bash initialisation was?

Many thanks,
Hu Jialun



reply via email to

[Prev in Thread] Current Thread [Next in Thread]