Chinaunix首页 | 论坛 | 博客
  • 博客访问: 164086
  • 博文数量: 18
  • 博客积分: 299
  • 博客等级: 二等列兵
  • 技术积分: 731
  • 用 户 组: 普通用户
  • 注册时间: 2011-02-19 00:39
文章分类

全部博文(18)

文章存档

2013年(7)

2012年(11)

分类: LINUX

2013-01-07 15:07:19

在上一篇文章当中,我们创建了lfs这个新建用户的组群,密码。更换toolssource文件夹的拥有者属性,最后,用login shell的方式切换到了lfs这个用户下面。


本章节,我们将创建lfs这个用户的环境变量。


(以下操作都在lfs下进行)



点击(此处)折叠或打开

  1. cat > ~/.bash_profile << "EOF"
  2. exec env -i HOME=$HOME TERM=$TERM PS1='\u:\w\$ ' /bin/bash
  3. EOF


  这句命令的意思是:在家目录新建一个叫.bash_profile的文件,并且以EOF为结尾,将exec 命令输入到.bash_profile这个文件里面去。 为什么要加这个命令呢?linux系统加载环境变量的时候,会先搜寻/etc/profile这个文件的环境变量,然后在加载.bash_profile这个文件。Exec env这个命令意思是重新用一个新的干净的环境变量,仅仅保留HOME,TERM,PS13个变量。 之前调用lfs的时候都是用login shell的,然而,也有会用none-login shell的时候,这个时候,shell不会调用/etc/profile.bash_profile,而是调用.bashrc 
创建.bashrc文件: 


点击(此处)折叠或打开

  1. cat > ~/.bashrc << "EOF"
  2. set +h umask 022 LFS=/mnt/lfs LC_ALL=POSIX LFS_TGT=$(uname -m)-lfs-linux-gnu PATH=/tools/bin:/bin:/usr/bin export LFS LC_ALL LFS_TGT PATH
  3. EOF


第一行cat
的意思前面解释过了,现在逐行解释下面每句话的含义:


点击(此处)折叠或打开

  1. set +h

关闭bashhash功能。shell原本的path是非常多的,所以它创造了一个hash的功能,这个功能将常用的命令跟路径结合在一起,下一次输入命令的时候直接在这个hash里面找就可以了,但是我们的lfs系统需要一个干净的环境,系统只想从$LFS/tools下找到相关的软件,而不是在其他路径上找。这个时候不需要hash功能了,因为hash可能会保存其他路径的执行软件。这个时候需要关闭hash功能。



ps: Hashman

hash [-lr] [-p filename] [-dt] [name]

For each name, the full file name of the command is determined

by searching the directories in $PATH and remembered. If the -p

option is supplied, no path search is performed, and filename is

used as the full file name of the command. The -r option causes

the shell to forget all remembered locations. The -d option

causes the shell to forget the remembered location of each name.

If the -t option is supplied, the full pathname to which each

name corresponds is printed. If multiple name arguments are

supplied with -t, the name is printed before the hashed full

pathname. The -l option causes output to be displayed in a for‐

mat that may be reused as input. If no arguments are given, or

if only -l is supplied, information about remembered commands is

printed. The return status is true unless a name is not found

or an invalid option is supplied.




点击(此处)折叠或打开

  1. umask 022

表示新建文件之后,屏蔽组群用户和其他用户的写权限。



点击(此处)折叠或打开

  1. LFS=/mnt/lfs LC_ALL=POSIX LFS_TGT=$(uname -m)-lfs-linux-gnu

第一个变量表示lfs系统的挂在的目录。

第二个变量表示保证在chroot环境下工作正常。

第三个变量表示当建立交叉编译环境的时候用于描述机器的。


最后,使得.bash_profile文件当前生效。

点击(此处)折叠或打开

  1. source ~/.bash_profile



阅读(2585) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~