Article View: gnu.bash.bug
Article #249Re: Differences between bash-1.12 and ksh88
From: Chet Ramey
Date: Mon, 03 Aug 1992 03:07
Date: Mon, 03 Aug 1992 03:07
224 lines
4933 bytes
4933 bytes
> 1) set options aren't local to a function
As Posix.2 specifies. With the bash way, it's possible to use aliases and
functions to implement things like a per-command `noglob' that are not
possible with ksh.
> 3) 'typeset -i i ; [ i=i+1 -gt 0 ]' doesn't work as expected
As Posix.2 specifies.
> 5) $(< file) doesn't work
Use $(cat file), as the Posix.2 spec suggests.
> 6) 'ENV_VAR=temp_value foo foo_args' doesn't work if foo is a shell function
Fixed for 1.13.
> 7) doesn't have a print command with the various options
I wrote a print function with all the various options. It's appended. In
fact, I have a whole ksh-compatability file that's appended.
> By the way, I'd care less about the typeset options (except for -l and -u) if
> there were a printf builtin (which would seem easy to implement). I use the
> 'printf' command I got off Usenet at times, but usually I don't want to expend
> the exec.
This doesn't belong in a shell. /usr/bin/printf is the way to go.
Chet
#
# .kshenv -- 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) fd=$OPTARG
;;
p|s) ;;
esac
done
shift $[ $OPTIND - 1 ]
builtin echo $eflag $nflag "$@" >&$fd
}
# substring function
# this function should be equivalent to the substring built-in which was
# eliminated after the 06/29/84 version
substring ()
{
local lpat flag str #local variables
set -f
case $1 in
-l|-L)
flag=$1
lpat=$2
shift 2
;;
esac
# test for too few or too many arguments
if [ x"$1" = x -o $# -gt 2 ]; then
print -u2 'substring: bad argument count'
return 1
fi
str=$1
if [ x"$flag" = x-l ]; then #substring -l lpat
str=${str#$lpat}
elif [ x"$flag" = x-L ]; then
str=${str##$lpat} #substring -L lpat
fi
if [ x"$2" != x ]; then
echo ${str%$2}
else
echo $str
fi
return 0
}
--
``The use of history as therapy means the corruption of history as history.''
-- Arthur Schlesinger
Chet Ramey, Case Western Reserve University Internet: chet@po.CWRU.Edu
Technical Details
Message-ID:
<9208031107.AA10483.SM@odin.INS.CWRU.Edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!odin.ins.cwru.edu!chetReferences:
chet@odin.ins.cwru.edu (Chet Ramey)Show Full Headers
Complete Article Headers
Newsgroups: gnu.bash.bug Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!odin.ins.cwru.edu!chet From: chet@odin.ins.cwru.edu (Chet Ramey) Subject: Re: Differences between bash-1.12 and ksh88 Message-ID: <9208031107.AA10483.SM@odin.INS.CWRU.Edu> Sender: gnulists@ai.mit.edu Reply-To: chet@po.cwru.edu Organization: GNUs Not Usenet References: chet@odin.ins.cwru.edu (Chet Ramey) Distribution: gnu Date: Mon, 3 Aug 1992 03:07:54 GMT Approved: bug-bash@prep.ai.mit.edu Lines: 225