I am trying to set PKG_CONFIG_PATH to CentOS here are the code I tried

export |grep PKG_CONFIG_PATH

no output, normal...


why there is output here??

and if I

sudo sh -c "echo 'export PKG_CONFIG_PATH=$PKG_CONFIG_PATH :/usr/local/lib/pkgconfig' >> /etc/profile.d/path.sh
source /etc/profile.d/path.sh

Now the same path will present twice........

export |grep PKG_CONFIG_PATH
declare -x PKG_CONFIG_PATH=:/usr/local/lib/pkgconfig:/usr/local/lib/pkgconfig

So if the path hasnt been setup yet where is that $PKG_CONFIG_PATH coming from?

Update Edit: The first part of the problem is not actually matters because after restarting the variables are cleared

For the really problem I think it is because the files inside profile.d are been called twice once by /etc/bashrc once by /etc/profile. One may ask WTH??Why is that happened?BUG??TYPO??


This is the difference between exported and non-exported environment variables.

The export command only lists exported environment variables, i.e. those variables that are marked as inheritable by child processes, either because the shell has inherited them from its parent process, or because the export or declare -x command has been used to mark them as exportable.

Non-exported variables are useful in scripts, as you can use them within the script, but they won't clutter the environment of any child processes.

To set a non-exported variable, you can use the name=value syntax alone:

$ FOO=bar
$ echo $FOO
export | grep FOO

You can later mark the variable as exportable:

$ export FOO
$ export | grep FOO
declare -x FOO="bar"

Classic Bourne shell in fact required you to initialized environment variables in this two-step fashion: first set the value, then mark it as exportable. So you may still see this syntax in shell scripts aiming for maximum portability:

export FOO

Modern shells allow doing it in a single step:

$ export FOO=bar

So, in your case, you must have had previously executed a PKG_CONFIG_PATH=:/usr/local/lib/pkgconfig, either manually, or within a sourced script, or as part of your login scripts.

| improve this answer | |
  • I am suspecting that too.May be at some point I set the environment variable without out export.But those should be temporary restart the system will remove those variable but it is not the case and I cant find it hard code written in any of the files. of course I can export PKG_CONFIG_PATH=:/usr/local/lib/pkgconfig exclusively but that means any of the pre existing path are not included(if there is by any chance) and it is not safe. – shadow_wxh May 15 '19 at 10:58
  • Adjustment.If I remove the line export PKG_CONFIG_PATH=$PKG_CONFIG_PATH :/usr/local/lib/pkgconfig both echo and export return nothing but if I add them back the path will show twice,see that problem. – shadow_wxh May 15 '19 at 11:26
  • Indeed it looks like your profile scripts are being executed twice: maybe once to initialize the X11 environment at GUI login (the shell that runs your ~/.Xsession script or the gnome-session command, or whatever desktop environment you're using), and then another time when opening a shell window?. – telcoM May 15 '19 at 13:06

Right now I have two solution:

  1. Remove these code from /etc/bashrc

    for i in /etc/profile.d/*.sh; do
      if [ -r "$i" ]; then
         if [ "$PS1" ]; then
            . "$i"
           . "$i" >/dev/null

    problem is I dont know why these code needs to be here in the first place there maybe some side effects after removing them.

  2. Just use direct assignment in /etc/profile.d/*.sh

    export PKG_CONFIG_PATH=:/usr/local/lib/pkgconfig

    of course this will exclude any preexisting path,not a standard practice.

Neither of them seems to be perfect solution any better suggestion?

Update :

Doing ① will cause this error message to appear after each command enter at the terminal

 bash: __vte_prompt_command: command not found
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.