0

I am trying to read a system variable that is XDG_CURRENT_DESKTOP from a shell script.

echo the variable in terminal works fine. but when running it within a bash script it echoes empty due to that the script runs from an child shell

I cannot export it, I don't know the source of the varible. is there any way to import a system variable without messing with bashrc?

/Pierre

2
  • Not sure exactly what you mean by, "... echoes empty due to that the script runs from an child shell" Are you saying you have a shell script that runs, "echo ${XDG_CURRENT_DESKTOP}" and if you run that script from a shell it prints out a blank line (i.e. XDG_CURRENT_DESKTOP is not set)?
    – Lewis M
    Nov 29, 2018 at 12:48
  • When you run a script, it runs in a subshell. Variables are only valid within the context of that subshell. and "system varibles" like XDG_CURRENT_DESKTOP are not included in the subshell, so no XDG_CURRENT_DESKTOP is not set in the subshell. Nov 30, 2018 at 9:26

0

You must log in to answer this question.

Browse other questions tagged .