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"
45 -*) echo "whence: bad option: $1"
51 if [ "$#" = "0" ] ; then
52 echo "whence: bad argument count"
58 if [ "$vflag" ] ; then
59 echo $(builtin type $cmd | sed 1q)
61 path=$(builtin type -path $cmd)
68 *) case "$(builtin type -type $cmd)" in
83 # For real ksh homeboy fanatics, redefine the `type' builtin with a ksh
94 0) builtin cd "$HOME" ;;
98 dir=$(echo "$PWD" | sed "s:$old:$new:g")
100 "$PWD") echo "bash: cd: bad substitution" >&2 ; return 1 ;;
106 *) echo "cd: wrong arg count" >&2 ; return 1 ;;
111 # ksh print emulation
113 # print [-Rnprsu[n]] [arg ...]
116 # -R BSD-style -- only accept -n, no escapes
117 # -n do not add trailing newline
118 # -p no-op (no coprocesses)
120 # -s no-op (print to the history file)
121 # -u n redirect output to fd n
131 while getopts "Rnprsu:" c
145 shift $[ $OPTIND - 1 ]
147 builtin echo $eflag $nflag "$@" >&$fd
151 # this function should be equivalent to the substring built-in which was
152 # eliminated after the 06/29/84 version
155 local lpat flag str #local variables
164 # test for too few or too many arguments
165 if [ x"$1" = x -o $# -gt 2 ]; then
166 print -u2 'substring: bad argument count'
170 if [ x"$flag" = x-l ]; then #substring -l lpat
172 elif [ x"$flag" = x-L ]; then
173 str=${str##$lpat} #substring -L lpat
176 if [ x"$2" != x ]; then