# /etc/kbashrc # System wide functions for ksh and bash # (Of course, this file must remain parsible for both ksh and bash) # --=-=-- # The argument for system functions vs. system aliases: # 1) aliases and functions can collide # Example: $ alias lk="less -c" # $ lk () { less -c $*; } # ksh: syntax error: (' unexpected # (note that in bash, you can get evil # circular definitions) # We need to standardize on one or the other. # 2) functions are more flexible than aliases # a) impossible alias: $ psg () { ps -p $2 | grep "$1"; } # b) functions can be redefined without error # c) users can define aliases that supersede functions: # $ unalias lk # $ lk () { less -c $*; } # $ alias lk="less -c" # $ type lk # lk is an alias for 'less -c' # pdksh # Functions are the better candidate for standardization. # 3) From the bash(1) man page: # "Aliases are not expanded when the shell is not interactive." # So, shell scripts that rely on aliases can fail in an "rsh". # # ***=-=>> Therefore, don't use system aliases -- use system functions. # # Thu Aug 15 02:56:33 PDT 1996: Scott Doty /sd # =============================================================== # Thu Aug 15 01:40:26 PDT 1996 -- # -- rewritten to work with ksh and bash # -- ("ksh" refers to "pdksh") # -- Lists in ksh functions must terminate with ";", # -- which bash will accept. /sd # The Function Definitions # rollcall for unaliasing and export # X aliases are in /etc/xkbashrc FUNCS="lk zlk nlk mslk cls ll lld rmtil pkzip which bye copy rmtilr" unalias ${FUNCS} > /dev/null 2>/dev/null # bash and ksh lk() { less -c $*; } # lk means "look at a file" (SRJC localism) zlk() { zcat $* | lk; } # lk at a compressed file nlk() { groff -Tascii -mandoc $* | lk; } # view an nroff doc mslk() { groff -Tascii -ms $* | lk; } # view an ms doc cls() { clear; } # clear the screen ll() { ls -l $*; } # classic lld() { ll $* | grep "^d"; } # ll directories rmtil() { rm -fv *~ && rm -fv .*~; } # remove tilde backup files rmtilr(){ find . -name '*~' | xargs rm -fv; } # Remove tilde backup files recursively bye() { exit; } # For CIS majors. =) copy() { cp $*; } # For DOS users. =) ck() { ps axw | fgrep "$*" | fgrep -v "fgrep $*" ;} editor() { EDITOR=$1; VISUAL=$1; export EDITOR VISUAL ;} #"which" is a special case, and is shell dependent. # relying on /usr/bin/which won't help, since it dumps # an error to (sheesh) stdout. Besides, it's slower than # the shell's builtin. case ${SHELL##*/} in ksh|pdksh) unalias which > /dev/null 2> /dev/null # "whence" is the builtin which () { whence $*; } ;; sh|bash) unalias which whence > /dev/null 2> /dev/null # "type" is the builtin which () { 'type' -p $*; } whence() { which $*; } typeset -fx whence ;; esac typeset -fx ${FUNCS} # bash and ksh function export unset FUNCS #export PRINCIPAL=`whoami` ;