Sessionsmiljøvariable

From KDE UserBase Wiki
Revision as of 19:50, 22 February 2017 by FuzzyBot (talk | contribs) (Updating to match new version of source page)

Sætning af sessionsmiljøvariable

It is simple to set environment variables that affect your whole session. Plasma will execute any script it finds in $HOME/.config/plasma-workspace/env whose filename ends in .sh, and it will maintain all the environment variables set by them. It is important that any variable you want to set must be also exported. In the case of PATH, for instance, your system will be set up with certain likely directories as the likely places to find things. Now you are adding an extra possible search place. You can see what is already set by opening Konsole and typing echo $PATH

To add paths to your PATH, simply create a file named $HOME/.config/plasma-workspace/env/path.sh with a contents similar to this:

export PATH=$HOME/local/bin:$PATH

Lad os se, hvad der sker her. Kommandoen export fortæller systemet, at dette er noget, som skal gemmes og bruges, når der søges efter filer. Herefter kommer den fulde sti til den mappe, som du ønsker at tilføje (i dette tilfælde ~/local/bin, hvilket er en anden måde at skrive /home/you/local/bin - nu kan du igen bruge echo $HOME til at se, hvordan det virker). Endelig ser du selve variablen, $PATH - det er fordi du føjer din nye sti til det eksisterende indhold i stedet for at overskrive det.

Ofte vil dette fungere godt nok for dig, men efterhånden som du bliver mere fortrolig med systemet, vil du nok ønske at have det samme miljø når du bruger en konsol eller tilgår maskinen via ssh; så skal du føje noget i retning af dette til slutningen af din .bashrc:

source $HOME/.config/plasma-workspace/env/path.sh

You can also check how Plasma actually does it. It's done in your local startkde, which normally you can find in /usr/bin/startkde. If you are interested in reading the code, you can can view it online. Just search the file for environment variables.