1 ########################################################################
3 # This software is part of the ast package #
4 # Copyright (c) 1982-2010 AT&T Intellectual Property #
5 # and is licensed under the #
6 # Common Public License, Version 1.0 #
7 # by AT&T Intellectual Property #
9 # A copy of the License is available at #
10 # http://www.opensource.org/licenses/cpl1.0.txt #
11 # (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) #
13 # Information and Software Systems Research #
17 # David Korn <dgk@research.att.com> #
19 ########################################################################
21 # bash compatibility startup script
25 # Omnium Software Engineering
30 # <K.Fleischer@omnium.de>
35 nameref FUNCNAME
=.sh.fun
51 if ! shopt -qo restricted
; then
55 [[ -n "$i" ]] && set -o $i
59 function SHELLOPTS.get
61 .sh.value
=$
(shopt -so)
62 .sh.value
=${.sh.value//+([[:space:]])on*([[:space:]])/:}
63 .sh.value
=${.sh.value%:}
66 set -A GROUPS $
(id
-G)
80 set -A .sh.value $
(dirs)
85 index
=_push_max-.sh.subscript
86 (( index
== _push_max || index
< _push_top
)) && return
87 _push_stack
[index
]=${.sh.value}
89 function DIRSTACK.
unset
93 unset -f DIRSTACK.
unset
98 typeset prefix remaining
=${.sh.value} var
= n
= k
=
99 while [[ $remaining ]]
100 do prefix
=${remaining%%'\'*}
101 remaining
=${remaining#$prefix}
103 case ${remaining:1:1} in
104 t
) var
+="\$(printf '%(%H:%M:%S)T')";;
105 d
) var
+="\$(printf '%(%a %b:%e)T')";;
109 W
) var
+="\$(basename \"\$(pwd)\")";;
111 h
) var
+=$
(hostname
-s);;
114 @
) var
+="\$(printf '%(%I:%M%p)T')";;
115 '$') if (( $
(id
-u) == 0 ))
121 [0-7]) case ${remaining:1:3} in
128 eval n="\$'"${remaining:0:k}"'"
130 remaining=${remaining:k}
134 *) var+='\'${remaining:0:2};;
136 remaining
=${remaining:2}
142 if shopt -q login_shell
; then
145 print
${BASH##*/}: $0: not login shell
: use
'exit' >&2
153 if ! shopt -qpo posix
; then
157 if shopt -q sourcepath
; then
172 typeset b cmd usage try_cmd man
173 function has_help_option
175 [[ $1 == @
(''|
/*|
:|
echo|false|true|login|
test|
'[') ]] && return 1
178 typeset
-A short_use
=(
179 [echo]='Usage: echo [ options ] [arg]...'
181 [true
]='Usage: true ...'
182 [false
]='Usage: false ...'
183 [login
]='Usage: login [-p] [name]'
184 ['[']='Usage: [ EXPRESSION ] | [ OPTION'
185 [test]='Usage: test EXPRESSION | test'
189 then print
'The following is the current list of built-in commands:'
190 print
-r $
'Type help *name* for more information about name\n'
192 do if has_help_option
$cmd
193 then usage
=$
($cmd --short 2>&1)
194 print
-r -- "${usage:7}"
195 else print
-r -- ${short_use[$cmd]:7}
202 [[ $1 == -s ]] && man
=--short && shift
204 do if has_help_option
$try_cmd
205 then if [[ $try_cmd == @
(${b//$'\n'/'|'}) ]]
209 elif [[ $man == '--short' ]]
210 then print
-r -- ${short_use[$try_cmd]}
225 if ! shopt -q cdable_vars
; then
228 msg
=$
(command cd "$@" 2>&1)
230 if [[ $ret != 0 ]]; then
234 -*) args
="$args $i" ;;
235 */*) args
="$args $i" ;;
237 if [[ -n $a ]]; then args
="$args $a"
253 ! shopt -qo posix
&& HISTFILE
=~
/.bash_history
255 nameref BASH_SUBSHELL
=.sh.subshell