7.5.环境列表(Environment List)

本文介绍了程序启动时接收的环境列表,包括其数据结构、如何通过全局变量environ访问环境变量及为何不再将环境列表作为main函数的第三个参数传递的原因。

7.5.环境列表(Environment List)

每一个程序也被传入一个环境列表。象参数列表(argument list)一样,环境列表也是一个字符指针的数组,其中每个指针指向一个以null结束的C字符串(null-terminated C string)。这个指针数组的地址被包含在全局变量environ中:
extern char **environ;
例如,如果环境由五个字符串组成,环境列表可能看起来象图7.5所示的那样。图中我们在每个字符串的末尾显式地表示出了null bytes。我们将把environ叫做环境指针(environment pointer),把指针数组叫做环境列表(environment list),把环境列表指向的字符串们叫做环境字符串(environment strings)。


图7.5.由5个C字符串组成的环境

按照惯例,环境由这样的字符串组成:name=value,就如同在图7.5中看到的那样。大多数人预先确定了name为全部大写,但是这仅是一个惯例。
一直以来,大部分的UNIX系统一直提供了第3个参数给main函数,这第3个参数就是环境列表的地址。如:
int main(int argc, char *argv[], char *envp[]);
因为ISO C指定了main函数只能用2个参数,但是因为提供第3个参数与使用全局变量environ相比,并没有什么优势,所以POSIX.1指定environ代替第3个参数envp。7.9节将会描述到,对某特定环境变量的存取正常情况下是通过函数getenv和putenv,而不是通过变量environ。但是要go through所有的环境,必须使用环境指针environ。


我这个有什么问题吗,为什么无法使用:usage: conda-script.py [-h] [-v] [--no-plugins] [-V] COMMAND ... conda is a tool for managing and deploying applications, environments and packages. options: -h, --help Show this help message and exit. -v, --verbose Can be used multiple times. Once for detailed output, twice for INFO logging, thrice for DEBUG logging, four times for TRACE logging. --no-plugins Disable all plugins that are not built into conda. -V, --version Show the conda version number and exit. commands: The following built-in and plugins subcommands are available. COMMAND activate Activate a conda environment. build Build conda packages from a conda recipe. clean Remove unused packages and caches. compare Compare packages between conda environments. config Modify configuration values in .condarc. content-trust Signing and verification tools for Conda convert Convert pure Python packages to other platforms (a.k.a., subdirs). create Create a new conda environment from a list of specified packages. deactivate Deactivate the current active conda environment. debug Debug the build or test phases of conda recipes. develop Install a Python package in 'development mode'. Similar to `pip install --editable`. doctor Display a health report for your environment. export Export a given environment index Update package index metadata files. info Display information about current conda install. init Initialize conda for shell interaction. inspect Tools for inspecting conda packages. install Install a list of packages into a specified conda environment. list List installed packages in a conda environment. metapackage Specialty tool for generating conda metapackage. notices Retrieve latest channel notifications. pack See `conda pack --help`. package Create low-level conda packages. (EXPERIMENTAL) remove (uninstall) Remove a list of packages from a specified conda environment. rename Rename an existing environment. render Expand a conda recipe into a platform-specific recipe. repo See `conda repo --help`. repoquery Advanced search for repodata. run Run an executable in a conda environment. search Search for packages and display associated information using the MatchSpec format. server See `conda server --help`. skeleton Generate boilerplate conda recipes. token See `conda token --help`. update (upgrade) Update conda packages to the latest compatible version.
最新发布
12-21
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值