Plan9 Environment Variables -- Notes of Introduction to OS Abstractions Using Plan 9 from Bell Labs(III)

    技术2022-05-20  40

    The interface for using environment variables in Plan 9 is a file interface. All interfaces of environment variables can be found under /env.

    To obtain the value for a environment variable, from a C program, we can use the getenv system call. If the variable is not defined, getenv returns a null string. A related call is putenv, which accepts a name and a value, and set the corresponding environment variable accordingly.

    #include <u.h> #include <libc.h> void main() { char * path; path=getenv("path"); if(path==nil) sysfatal("path not defined!"); print("PATH is %s /n", path); exits(nil); } 

     

    In some cases it is convenient to define an environment variable just for a command. This can be done by defining it in the same command line, before the command, like in the following exam-ple:

    ; temp=/tmp/foobar echo $temp /tmp/foobar ; echo $temp ;  

    Useful Environment Variables:

    status is updated by the shell once it finds out how it went to the last command it executed.

    path is a list of paths where the shell should look for executable files to run the user commands.

    user contains the user name .

    sysname contains the machine name.

    The file /dev/text represents the text shown in the window (when used within that window). To make a copy of your shell session, you already know what to do:

    ; cp /dev/text $home/saved

    The same can be done for the image shown in the display for your window, which is also represented as a file, /dev/window. This is what we did to capture screen images .

     


    最新回复(0)