From 7f58c46de6ecdf55af3a82112aa2a047ff9ca8be Mon Sep 17 00:00:00 2001 From: "William F. Jolitz" Date: Tue, 31 Dec 1991 09:51:51 -0800 Subject: [PATCH] 386BSD 0.1 development Work on file usr/othersrc/public/bash-1.12/bash-1.12/examples/functions/ksh-compat.~1~ Co-Authored-By: Lynne Greer Jolitz Synthesized-from: 386BSD-0.1 --- .../examples/functions/ksh-compat.~1~ | 153 ++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 usr/othersrc/public/bash-1.12/bash-1.12/examples/functions/ksh-compat.~1~ diff --git a/usr/othersrc/public/bash-1.12/bash-1.12/examples/functions/ksh-compat.~1~ b/usr/othersrc/public/bash-1.12/bash-1.12/examples/functions/ksh-compat.~1~ new file mode 100644 index 0000000000..cd44ebaca3 --- /dev/null +++ b/usr/othersrc/public/bash-1.12/bash-1.12/examples/functions/ksh-compat.~1~ @@ -0,0 +1,153 @@ +# +# ksh-compat -- functions and aliases to provide the beginnings of a ksh +# environment for bash. +# +# Chet Ramey +# chet@ins.CWRU.Edu +# +# +# These are definitions for the ksh compiled-in `exported aliases'. There +# are others, but we already have substitutes for them: "history", "type", +# and "hash". +# +alias r="fc -e -" +alias functions="typeset -f" +alias integer="typeset -i" +alias nohup="nohup " +alias true=":" +alias false="let 0" + +# +# An almost-ksh compatible `whence' command. This is as hairy as it is +# because of the desire to exactly mimic ksh (whose behavior was determined +# empirically). +# +# This depends somewhat on knowing the format of the output of the bash +# `builtin type' command. +# + +whence () +{ + local vflag + local path + + vflag= + path= + + if [ "$#" = "0" ]; then + echo "whence: argument expected" + return 1 + fi + + case "$1" in + -v) vflag=1 + shift 1 + ;; + -*) echo "whence: bad option: $1" + return 1 + ;; + *) ;; + esac + + if [ "$#" = "0" ]; then + echo "whence: bad argument count" + return 1 + fi + + for cmd; do + if [ "$vflag" ]; then + echo $(builtin type $cmd | sed 1q) + else + path=$(builtin type -path $cmd) + + if [ "$path" ]; then + echo $path + else + case "$cmd" in + /*) echo "" + ;; + *) + case "$(builtin type -type $cmd)" in + "") echo "" + ;; + *) echo "$cmd" + ;; + esac + ;; + esac + fi + fi + done + return 0 +} + +# +# For real ksh homeboy fanatics, redefine the `type' builtin with a ksh +# version. +# +#type() +#{ +# whence -v "$*" +#} + +cd () +{ + case $# in + 0) builtin cd "$HOME" ;; + 1) builtin cd "$@" ;; + 2) old="$1" + new="$2" + dir=$(echo "$PWD" | sed "s:$old:$new:g") + case "$dir" in + "$PWD") echo "bash: cd: bad substitution" >&2 + ;; + *) echo "$dir" + builtin cd "$dir" + ;; + esac + ;; + *) echo "cd: wrong arg count" >&2 + ;; + esac +} + +# +# ksh print emulation +# +# print [-Rnprsu[n]] [arg ...] +# +# - end of options +# -R BSD-style -- only accept -n, no escapes +# -n do not add trailing newline +# -p no-op (no coprocesses) +# -r no escapes +# -s no-op (print to the history file) +# -u n redirect output to fd n +# + +print() +{ + local eflag=-e + local nflag= + local fd=1 + + OPTIND=1 + while getopts "Rnprsu:" c + do + case $c in + R) eflag= + ;; + r) eflag= + ;; + n) nflag=-n + ;; + u) redir=">&$OPTARG" + fd=$OPTARG + ;; + p|s) ;; + esac + done + shift $[ $OPTIND - 1 ] + + echo $eflag $nflag "$@" >&$fd +} -- 2.20.1