2 # .kshenv -- functions and aliases to provide the beginnings of a ksh
3 # environment for bash.
9 # These are definitions for the ksh compiled-in `exported aliases'. There
10 # are others, but we already have substitutes for them: "history", "type",
14 alias functions="typeset -f"
15 alias integer="typeset -i"
22 # An almost-ksh compatible `whence' command. This is as hairy as it is
23 # because of the desire to exactly mimic ksh (whose behavior was determined
26 # This depends somewhat on knowing the format of the output of the bash
27 # `builtin type' command.
37 if [ "$#" = "0" ] ; then
38 echo "whence: argument expected"
42 -v) vflag=1 ; shift 1 ;;
43 -*) echo "whence: bad option: $1" ; return 1 ;;
47 if [ "$#" = "0" ] ; then
48 echo "whence: bad argument count"
54 if [ "$vflag" ] ; then
55 echo $(builtin type $cmd | sed 1q)
57 path=$(builtin type -path $cmd)
63 *) case "$(builtin type -type $cmd)" in
76 # For real ksh homeboy fanatics, redefine the `type' builtin with a ksh
87 0) builtin cd "$HOME" ;;
91 dir=$(echo "$PWD" | sed "s:$old:$new:g")
93 "$PWD") echo "bash: cd: bad substitution" >&2 ; return 1 ;;
99 *) echo "cd: wrong arg count" >&2 ; return 1 ;;
104 # ksh print emulation
106 # print [-Rnprsu[n]] [arg ...]
109 # -R BSD-style -- only accept -n, no escapes
110 # -n do not add trailing newline
111 # -p no-op (no coprocesses)
113 # -s print to the history file
114 # -u n redirect output to fd n
124 while getopts "Rnprsu:" c
135 shift $[ $OPTIND - 1 ]
138 y) builtin history -s "$*" ;;
139 *) builtin echo $eflag $nflag "$@" >&$fd
144 # this function should be equivalent to the substring built-in which was
145 # eliminated after the 06/29/84 version
148 local lpat flag str #local variables
157 # test for too few or too many arguments
158 if [ x"$1" = x -o $# -gt 2 ]; then
159 print -u2 'substring: bad argument count'
163 if [ x"$flag" = x-l ]; then #substring -l lpat
165 elif [ x"$flag" = x-L ]; then
166 str=${str##$lpat} #substring -L lpat
169 if [ x"$2" != x ]; then