if (argv[0] && argv[0][0] == '-')
isloginsh = 1;
if (isloginsh) {
state = 1;
read_profile("/etc/profile");
state1:
state = 2;
read_profile(".profile");
}
如上,busybox中ash对全局环境变量/etc/profile文件的处理就是这样。
如果shell为登陆shell,则读取全局环境变量文件,否则不读取。是否为登陆shell,则以
if (argv[0] && argv[0][0] == '-')
定义,即如果第一个参数存在,并且以“-”开头,则为登陆shell,所以,如果想在shell启动时读取全局环境变量,则需传递shell参数时,在第一个参数前加上“-”