|
1952 | 1952 | %%%%% |
1953 | 1953 |
|
1954 | 1954 | \begin{slide} |
1955 | | -\sltitle{Promìnné prostøedí} |
| 1955 | +\sltitle{Environment variables} |
1956 | 1956 | \begin{itemize} |
1957 | | -\item seznam v¹ech promìnných prostøedí (\emph{environment |
1958 | | -variables}) se pøedává jako promìnná\\ \texttt{extern char |
| 1957 | +\item the list of \emph{environment |
| 1958 | +variables} is passed as\\ \texttt{extern char |
1959 | 1959 | **\funnm{environ};} |
1960 | | -\item je to pole ukazatelù (ukonèené NULL) na øetìzce ve tvaru:\\ |
1961 | | -\texttt{\emph{promìnná}=\emph{hodnota}} |
| 1960 | +\item it is an array of strings terminated by \texttt{NULL} of the |
| 1961 | +format: \texttt{\emph{variable\_name}=\emph{value}} |
1962 | 1962 | \end{itemize} |
1963 | 1963 | \begin{center} |
1964 | 1964 | \input{img/tex/environ.pstex_t} |
1965 | 1965 | \end{center} |
1966 | 1966 | \end{slide} |
1967 | 1967 |
|
1968 | 1968 | \begin{itemize} |
1969 | | -\item shell pøedává spu¹tìnému programu ty promìnné, které jsou oznaèeny jako |
1970 | | -exportované (Bourne-like shellech pøíkazem \texttt{export \emph{variable}}). Po |
1971 | | -zmìnì obsahu ji¾ jednou exportované promìnné samozøejmì není potøeba promìnnou |
1972 | | -znovu exportovat. Pøíkaz \texttt{env} vám vypí¹e aktuální promìnné |
1973 | | -prostøedí. |
1974 | | -Abyste pøidali promìnnou do prostøedí spou¹tìného programu staèí provést |
1975 | | -pøiøazení na pøíkazové øádce, ani¾ byste museli mìnit prostøedí va¹eho |
1976 | | -shellu: |
| 1969 | +\item A shell passes an executed program those variables marked as exported |
| 1970 | +(in Bourne-like shells via an internal command \texttt{export \emph{variable}}). |
| 1971 | +After you export a variable, you do not need to export it again after its value |
| 1972 | +is changed. The command \texttt{env} prints current enviroment variables. |
| 1973 | +You can also add a variable to the environment of an executed program without |
| 1974 | +changing the environment of your current shell: |
| 1975 | + |
1977 | 1976 | \begin{verbatim} |
1978 | 1977 | $ date |
1979 | 1978 | Sun Oct 7 13:13:58 PDT 2007 |
1980 | 1979 | $ LC_TIME=fr date |
1981 | 1980 | dimanche 7 octobre 2007 13 h 14 PDT |
1982 | 1981 | \end{verbatim} |
1983 | 1982 |
|
1984 | | -nedivte se, pokud to na va¹em systému takto fungovat nebude, v tom pøípadì |
1985 | | -nemáte instalovaný balík s francouzskou lokalizací (co¾ je pravdìpodobné). |
1986 | | -\item pøi nahrazení aktuálního obrazu procesu obrazem jiným se pøedává, pokud |
1987 | | -se neøekne jinak, synovským procesùm celé pole \texttt{environ} automaticky. |
1988 | | -Je mo¾né ve volání pøíslu¹né varianty funkce \texttt{exec} pøedat pole jiné. |
1989 | | -\item jaké promìnné prostøedí konkrétní pøíkaz pou¾ívá (a jak je pou¾ívá) by |
1990 | | -mìlo být v manuálové stránce. Typicky v sekci nazvané \emph{ENVIRONMENT} nebo |
1991 | | -\emph{ENVIRONMENT VARIABLES} |
1992 | | -\item \texttt{man} napøíklad pou¾ívá \texttt{PAGER}, \texttt{vipw} pak |
1993 | | -promìnnou \texttt{EDITOR} apod. |
1994 | | -\item pokud je \texttt{envp} tøetím parametrem funkce \texttt{main}, tak je to |
1995 | | -stejná hodnota co je v ukazateli \texttt{environ}. |
1996 | | -\item pøíklad: \example{main/print-env.c} (vèetnì pou¾ití |
1997 | | -\texttt{env} pøíkazu zpùsobem, který vyèistí zdìdìné promìnné prostøedí). |
| 1983 | +It may not work like that in your shell as very probably your system will not |
| 1984 | +have a french localization package installed. |
| 1985 | +\item When replacing the current process image with a different program (page |
| 1986 | +\pageref{EXEC}), the child will by default get the full environment from its |
| 1987 | +parent. You can pass a different array as an argument to the function |
| 1988 | +\texttt{exec()}, including passing an empty one. |
| 1989 | +\item Different commands use different environment variables. That should be |
| 1990 | +documented in their respective manual pages, sometimes in a separate section |
| 1991 | +named \emph{ENVIRONMENT} or \emph{ENVIRONMENT VARIABLES}. |
| 1992 | +\item For example, the \texttt{man} command uses \texttt{PAGER}, \texttt{vipw} |
| 1993 | +uses \texttt{EDITOR} etc. The variables are usually in caps but it is just a |
| 1994 | +convension. \texttt{wget} does not follow that, for example, it uses |
| 1995 | +\texttt{http\_proxy} and \texttt{https\_proxy} as environment variables to set |
| 1996 | +the proxy to be used, and other lower case variables as well. |
| 1997 | +\item If \emph{envp} is the 3rd argument of \texttt{main} it is the same pointer |
| 1998 | +as is in the standard global variable \texttt{environ}. |
| 1999 | +\item Example: \example{main/print-env.c} (see below how to clear out inherited |
| 2000 | +environment from the shell using the \texttt{env} command): |
| 2001 | + |
1998 | 2002 | \begin{verbatim} |
1999 | 2003 | $ cc print-env.c |
2000 | 2004 | $ env - XXX=yyy aaa=ABC ./a.out |
|
0 commit comments