- 论坛徽章:
- 0
|
在脚本中是可以使用alias 的,只是bash 在非交互式shell中黙认把alias关闭了,打开就是了
以下是测试代码,bash,zsh,ksh 执行结果一样
- sh=$(readlink -f /proc/$/exe)
- sh=$(basename $sh)
- if [ "$sh" = "bash" ];then
- shopt -s expand_aliases
- elif [ "$sh" = "zsh" ];then
- # in my system, this is not needed
- set +o noaliases
- # ksh ,what ?
- fi
- alias echo='/bin/echo -e'
- echo "\n\naaa\n\tbbbbbb"
- alias ls='/bin/ls -a'
- ls /
- alias df='/bin/df -h'
- df
复制代码 这是我的shell版本
- % bash --version
- GNU bash, version 4.0.33(2)-release (i586-mandriva-linux-gnu)
- Copyright (C) 2009 Free Software Foundation, Inc.
- License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
- This is free software; you are free to change and redistribute it.
- There is NO WARRANTY, to the extent permitted by law.
- % zsh --version
- zsh 4.3.10 (i586-mandriva-linux-gnu)
- % rpm -qf /usr/bin/ksh
- pdksh-5.2.14-27mdv2010.0
复制代码 |
|