LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 2414|回复: 6

gentoo下 bash 的alias不能传递给子进程

[复制链接]
发表于 2003-2-6 16:25:32 | 显示全部楼层 |阅读模式
我的gentoo 的 init 是3, 启动起来后,使用 alias 命令可以看到已经定义了很多个 alias (定义在 /etc/profile 以及 ~/.bashrc 中), 但是, startx, 启动起 kde 3.1 后,开一个 konsole , alias 就一个都没有了!

我启动 TWM ,在其中的 xterm 中,也是这样

我在 mandrake 下是完全正常的

请诸位指点
发表于 2003-2-6 16:40:05 | 显示全部楼层
/etc/profile 和
~/.bash_profile
是在启动一个交互登陆shell的时候被调用。~/.bashrc
是在一个交互的非登陆shell启动的时候被调用。

你看看是不是你需要的alias都被调用过了。
 楼主| 发表于 2003-2-6 17:06:44 | 显示全部楼层
~/.bashrc 和 /etc/profile 中,都有 alias 定义的,而在X 下的 console 中, 一个alias 也没有的

而我可以通过 export 看到, environment variables 是全都有的(也在上述2个文件中定义的), 所以我确信这2个文件都被执行了
 楼主| 发表于 2003-2-6 17:53:14 | 显示全部楼层
终于找到解决办法了:
在 konsole -> settings -> configure konsole -> session 下,在左下的 session 列表中,选择 shell (这个是默认的打开类型),你可以看到 Execute 栏现在是空的, 在其中填入

/bin/bash --login

别忘了按 OK

这样,你以后在konsole 中打开的session 的环境,都和你刚刚进入 init 3 时是一样的了
发表于 2003-2-7 00:45:03 | 显示全部楼层
你这样作实际上是将这个
本来是非登陆SHELL的BASH设置成了一个登陆SHELL
你的ALIAS在登陆SHELL里面可以用但是非登陆用不了么,这样也是一个曲线救国的方法了。:)
发表于 2003-2-7 00:46:10 | 显示全部楼层
还有就是你调用一个XTERM有没有ALIAS呢,看样子是设置了KONSOLE,其他的可能还有些小毛病。
发表于 2003-2-7 03:05:37 | 显示全部楼层
既然是这个主题我就顺便贴一个SHELL配置的文章吧,这个文章在GOOGLE上随处可见,看来我们网站之间的CP可真是。。。。既然大家都有我们这里也不能没有喽。

这个文章和我们即将出现的BLFS里面的介绍互有补充。特别是对INPUTRC的介绍和一些BASH里面的小函数可以借鉴。

-----------------------------------------------------------

下列设置档必需加以设定:/etc/profile /etc/bashrc .bashrc .bashrc .bash_profile .bash_logout .inputrc .less .lessrc .xinitrc .fvwmrc .fvwm2rc95 .Xmodmap .Xmodmap.num .Xdefaults .jedrc .abbrevs.sl .joerc .emacs . 在完成系统设定以前不要增添用户;需要将点文档(dot files)放入/etc/skel。


4.1 bash(1)
有人认为,这个软件是除内核之外最重要的软件。要使bash适合个人口味,可修改下列文档:


/etc/bashrc 存有整个系统的别名和功能;
/etc/profile 存有整个系统的环境参数和启动程序;
$HOME/.bashrc 存有用户的的别名和功能;
$HOME/.bash_profile 存有用户的环境参数和启动程序;
$HOME/.inputrc 存有主要绑定数值和其他位元数值;
下文例举对这些文档的修改。首先,最重要的文档是:/etc/profile。以下几节中可以看到,修改这个文档可以设定 Linux 的各种功能。



--------------------------------------------------------------------------------

# /etc/profile

# System wide environment and startup programs
# --整个系统环境和启动程序
#
# Functions and aliases go in /etc/bashrc
# --/etc/bashhrc中包含功能和别名
#
# This file sets up the following features and programs:
# --这个文档设定下列功能:
#
#   o path --路径
#   o prompts  --提示符
#   o a few environment variables  --几个环境变数
#   o colour ls --ls 的颜色
#   o less behaviour    --设定less的功能
#   o rxvt
#
# Users can override these settings and/or add others in their
# $HOME/.bash_profile
# 用户可在 $HOME/.bash_profile 中取消这些设定和(或)增加其他设定


# set a decent path
# 设定可行的路径

PATH="$PATH:/usr/X11R6/binHOME/bin:."

# notify the user: login or non-login shell. If login, the prompt is
# coloured in blue; otherwise in magenta. Root's prompt is red.
# See the Colour-ls mini  HOWTO  for an explanation of the escape codes.
# 通知用户:登录(login)或不登录(non-login)的外围程序(shell)。
# 如果登录,则提示符为蓝色,否则为紫红色。Root的提示符为红色。
# 参阅Colour-ls mini  HOWTO 中对换码符(escape codes)的使用解释。

USER=`whoami`
if [ $LOGNAME = $USER ] ; then
  COLOUR=44  # blue --蓝色
else
  COLOUR=45  # magenta --紫红色
fi

if [ $USER = 'root' ] ; then
  COLOUR=41  # red --红色
  PATH="$PATH:/usr/local/bin"
fi

ESC="\033"
PROMPT='\h'    # hostname --主机名
STYLE=';1m'    # bold --粗体
# PROMPT='\u'  # username --用户名
# STYLE='m'    # plain --一般字体
PS1="\[$ESC[$COLOUR;37$STYLE\]$PROMPT:\[$ESC[37;40$STYLE\]\w\\$ "
PS2="> "

# no core dumps, please
# 请勿转储内存信息

ulimit -c 0

# set umask
# 设定umask

if [ `id -gn` = `id -un` -a `id -u` -gt 14 ]; then
  umask 002
else
  umask 022
fi

# a few variables
# 几项变数

USER=`id -un`
LOGNAME=$USER
MAIL="/var/spool/mail/$USER"  # sendmail, postfix, smail
# MAIL="$HOME/Mailbox"        # qmail
NNTPSERVER=news.myisp.it      # put your own here
VISUAL=jed
EDITOR=jed
HOSTNAME=`/bin/hostname`
HISTSIZE=1000
HISTFILESIZE=1000
export PATH PS1 PS2 USER LOGNAME MAIL NNTPSERVER
export VISUAL EDITOR HOSTNAME HISTSIZE HISTFILESIZE

# enable colour ls
# 设定ls的颜色

eval `dircolors /etc/DIR_COLORS -b`
export LS_OPTIONS='-s -F -T 0 --color=yes'

# customize less
# 设定less

LESS='-M-Q'
LESSEDIT="%E ?lt+%lt. %f"
LESSOPEN="| lesspipe.sh %s"
LESSCHARDEF=8bcccbcc13b.4b95.33b. # show colours in ls -l | less
# LESSCHARSET=latin1
PAGER=less
export LESS LESSEDIT LESSOPEN VISUAL LESSCHARDEF

# fix the backspace key in rxvt/xterm
# 设定rxvt/xterm中的退後键

CTRL_H="\010"
NULL_STRING=" $CTRL_H" # space + backspace
if [ "$NULL_STRING" != "" ] ; then
  stty erase ^?
else
  stty erase ^H
fi

# set xterm title: full path
case $TERM in
  xterm*)
    PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"'
    ;;
esac

for i in /etc/profile.d/*.sh ; do
  if [ -x $i ]; then
    . $i # beware - variables and aliases might get overridden!
  fi
done

# call fortune, if available  --如有fortune
if [ -x /usr/games/fortune ] ; then
  echo ; /usr/games/fortune ; echo
fi


--------------------------------------------------------------------------------

此处为 /etc/bashrc:



--------------------------------------------------------------------------------

# /etc/bashrc

# System wide functions and aliases
# 整个系统的功能和别名
#
# Environment stuff goes in /etc/profile
# /etc/profile中的环境参数
#
# Insert PS1 definitions here if you experience problems.
# 如有问题可将PS1的参数放在此处

export CDPATH="$CDPATH:

# common aliases --共同别名

alias cp='cp -i'
alias l=less
alias ls="ls $LS_OPTIONS"
alias mv='mv -i'
alias rm='rm -i'
alias rmbk='/bin/rm -f .*
alias u='cd ..'
alias which="type -path"
alias x=startx

# A few useful functions --几项有用的功能

c ()    # cd to the new directory and list its contents
{
  cd $1 ; ls
}

inst()  # Install a .tar.gz archive in current directory --在当前目录中建立.tar.gz储存库
{
  if [ $# != 0 ]; then tar zxvf $1; fi
}

cz()    # List the contents of a .zip archive --列出.zip的内容
{
  if [ $# != 0 ]; then unzip -l $*; fi
}

ctgz()  # List the contents of a .tar.gz archive --列出.tar.gz的内容
{
  for file in $* ; do
    tar ztf ${file}
  done
}

tgz()   # Create a .tgz archive a la zip. --建立压缩档.tgz
{
  if [ $# != 0 ]; then
    name=$1.tar; shift; tar -rvf ${name} $* ; gzip -9 ${name}
  fi
}

crpm()  # list information on an .rpm file --列出.rpm档的内容
{
  if [ $# != 0 ]; then rpm -qil $1 | less; fi
}


--------------------------------------------------------------------------------

此处为 .bashrc:



--------------------------------------------------------------------------------

# $HOME/.bashrc
# Source global definitions

if [ -f /etc/bashrc ]; then
  . /etc/bashrc
fi

# this is needed to notify the user that they are in non-login shell
# 需要以下设定,以便通知处於不登录(non-login)外围程序(shell)中的用户

if [ "$GET_PS1" = "" ] ; then
  COLOUR=45; ESC="\033"; STYLE=';1m';  # STYLE='m'
  USER=`whoami`
  export PS1="\[$ESC[$COLOUR;37$STYLE\]$USER:\[$ESC[37;40$STYLE\]\w\\$ "
fi

# personal aliases
# 个人别名

alias backup='tar -Mcvf /dev/fd0'
alias dial='eznet up myisp'
alias f='cd
alias hangup='eznet down'
alias lyx='lyx -width 580 -height 450'
alias restore='tar -M -xpvf /dev/fd0'

# personal functions
# 几个个人使用的功能

xj()    # Launch xjed and a file in background --在背景启动xjed和文档
{
  xjed $1 &
}


--------------------------------------------------------------------------------

此处为.bash_profile:



--------------------------------------------------------------------------------

# $HOME/.bash_profile

# User specific environment and startup programs
# 用户特定的环境参数和启动程序
#
# This file contains user-defined settings that override
# those in /etc/profile
# 这个文档中存有用户自订的设置,可取代/etc/profile 中的数值
#
# Get aliases and functions
# 设定别名和功能
#
if [ -f  then
  GET_PS1="NO"  # don't change the prompt colour --不改变提示符的颜色
  .
fi

# set a few `default' directories
# 设定几个“默认”目录

export CDPATH="$CDPATHHOMEHOME/textHOME/text/geology"


--------------------------------------------------------------------------------

此处为 .inputrc:



--------------------------------------------------------------------------------

# $HOME/.inputrc

# key bindings
# 主要绑定

"\e[1
"\e[3
"\e[4
# (F1 .. F5) are "\e[[A" ... "\e[[E"
# (F1 .. F5) 分别为 "\e[[A" ... "\e[[E"

"\e[[A": "info \C-m"

set bell-style visible          # please don't beep
                                # 喇叭不发声
set meta-flag On                # allow 8-bit input (i.e, accented letters)
                                # 允许8-位元输入(例如重音字符)译注:用于欧洲

set convert-meta Off            # don't strip 8-bit characters
                                # 不取消8-位元字符
set output-meta On              # display 8-bit characters correctly
                                # 正确显示8-位元字符
set horizontal-scroll-mode On   # scroll long command lines
                                # 长指令行自动翻转
set show-all-if-ambiguous On    # after TAB is pressed
                                # 按TAB键


--------------------------------------------------------------------------------

设定下列参数使 backspace 和 delete 两键在xterm 和其他X11应用中运作正常:

在.xinitrc中添加:
usermodmap=$HOME/.Xmodmap
xmodmap $usermodmap

在.Xmodmap中添加:
keycode 22 = BackSpace
keycode 107 = Delete

以上就设定了主控台的参数。要修改xterm,则更改如下:
在.Xdefaults中增添:
xterm*VT100.Translations: #override <Key>BackSpace: string(0x7F)\n\
        <Key>Delete:        string(0x1b) string("[3
        <Key>Home:          string(0x1b) string("[1
        <Key>End:           string(0x1b) string("[4
        Ctrl<Key>rior:     string(0x1b) string("[40
        Ctrl<Key>Next:      string(0x1b) string("[41

nxterm*VT100.Translations: #override <Key>BackSpace: string(0x7F)\n\
        <Key>Delete:        string(0x1b) string("[3
        <Key>Home:          string(0x1b) string("[1
        <Key>End:           string(0x1b) string("[4
        Ctrl<Key>rior:     string(0x1b) string("[40
        Ctrl<Key>Next:      string(0x1b) string("[41

rxvt的问题比较复杂,因为在编辑时的一些设定会影响它的功能。参看上文 /etc/profile部分。

在bash(1) 和 readline(3) 的 man 说明中有更多这方面的资料。

不要以为这些设定在每种应用中都可正常运作。例如,在xterm中运行joe,有些键位就不起作用;运行rxvt也有相同的问题。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表