blob: 32572f0ea07dae6cb6082bd2639c989a9c6b2c01 [file] [log] [blame]
Johnothan Kingb0691b42025-05-21 21:21:14 +02001#!/bin/ksh
2
3# Rendering namespace variables
4echo ${.foo.bar[adsf]} ${foo.bar[1][2]} ${foo.bar[1][az]} ${.foo.bar[1][2]}
5echo ${.foo[var]} ${.foo.bar[1]} ${.foo.bar[*]} ${foo.bar##baz} ${.foo.bar##baz}
6echo ${.foo.bar[3]##baz} ${.foo.bar[z]##baz} ${sh.version/V/b} ${.sh.version/V/b}
7echo ${foo/%bar/foo} ${foo/#bar/foo} ${foo.bar/%bar/foo} ${foo.bar[d]/#bar/foo}
8echo ${.foo/%barfoo} ${.foo.bar/#bar/foo} ${.bar.foo/%bar/foo} ${.bar/#bar/foo}
9echo ${foo/%barfoo} ${foo/bar/foo} ${barfoo//bar/foo} ${bar/#bar/foo}
10echo ${.sh.version^^} ${.sh.version,,} ${KSH_VERSION^} ${KSH_VERSION,}
11
12# 'alarm' builtin (present in ksh93u+, ksh93v- and the 93u+m dev branch).
13alarm --man
14# The fds and pids builtins. These ksh93 builtins have existed since 2005-05-22
15# and 2008-06-02, respectively. However, these were not readily enabled; in
16# 93u+m these can be enabled with the builtin command if libcmd.so is present,
17# either via 'builtin -f' or (in more recent commits) with a regular invocation
18# of the 'builtin' built-in.
19# cf. https://github.com/ksh93/ksh/commit/f15e2c41
20builtin fds pids
21fds; pids
22
23# Unix commands which are provided by ksh as builtins via libcmd.so
24basename
25cat
26chgrp
27chmod
28chown
29cksum
30cmp
31comm
32cp
33cut
34date
35dirname
36egrep # Obsolescent
37expr
38fgrep # Obsolescent
39fmt
40fold
41getconf
42grep
43head
44iconv # 93v-
45id
46join
47ln
48logname
49ls # 93v-
50md5sum
51mkdir
52mkfifo
53mktemp
54mv
55od # 93v-
56paste
57pathchk
58readlink # 93v-
59realpath # 93v-
60rev
61rm
62rmdir
63sha1sum # 93v-
64sha256sum # 93v-
65sha2sum # 93v-
66sha384sum # 93v-
67sha512sum # 93v-
68stty
69sum
70sync
71tail
72tee
73tr # 93v-
74tty
75uname
76uniq
77vmstate # Obsolescent; only available in 93v- and older
78wc
79xargs # 93v-
80xgrep # 93v-
81
82# SHA command not provided as a builtin but included here for completeness
83sha224sum
84
85# poll builtin (93v-)
86poll --man
87
88# mkservice and eloop (rarely provided; requires SHOPT_MKSERVICE)
89mkservice --man; eloop --help
90
91# some mksh builtins
92bind; rename
93
94# ;& and ;;& in case statements
95case x in
96 bar) false ${baz:1} ;&
97 foo) true ${foo:0:0} ;;&
98 *) print ${bar} ;;
99esac
100
101# Below is subshare syntax supported by both ksh93 and mksh.
102print ${ echo one }
103print ${ echo two
104}
105print ${
106echo three }
107print ${ echo 'four'; }
108print ${ echo 'five' ;}
109print ${ echo 'six'
110}
111print ${ echo 'seven' }
112echo ${ print 'eight' }
113typeset nine=${ pwd; }
114
115# Value substitutions of the form ${|command} are only
116# supported by mksh, not ksh93.
117if ! command eval '((.sh.version >= 20070703))' 2>/dev/null; then
118 valsubfunc() {
119 REPLY=$1
120 }
121 echo ${|valsubfunc ten}
122 print "${|valsubfunc eleven;}"
123 printf '%s' "${|valsubfunc twelve }"
124 unlucky=${|valsubfunc thirteen
125}
126 typeset notafloat=${|valsubfunc notanumber }
127 print $unlucky $notanumber
128 ${|echo foo}
129 ${|echo bar
130}
131fi
132
133# ======
134# Shared-state command substitutions using the syntax ${<file;}
135# are only supported by ksh93, not mksh.
136echo ${
137 printf %s str
138} > /tmp/strfile
139echo ${</tmp/strfile;}
140
141exit 0
142# ksh88 and ksh93 non-dot special variables
143print ${ RANDOM= SRANDOM= SHLVL= JOBMAX= KSH_VERSION= FIGNORE= LC_TIME= LC_NUMERIC= LC_MESSAGES= LC_CTYPE= LC_COLLATE= LC_ALL= LANG= FPATH= PS4= OPTIND= OPTARG= true ;}
144print $(LINENO= SECONDS= TMOUT= PPID= LINES= COLUMNS= VISUAL= OLDPWD= PS3= MAILPATH= CDPATH= FCEDIT= HISTCMD= HISTEDIT= HISTSIZE= HISTFILE= ENV= MAILCHECK= EDITOR= SHELL= false)
145print $(REPLY= MAIL= HOME= PWD= IFS= PS2= PS1= PATH= SH_OPTIONS= ERRNO= COMP_CWORD= COMP_LINE= COMP_POINT= COMP_WORDS= COMP_KEY= COMPREPLY= COMP_WORDBREAKS= COMP_TYPE= compgen)
146print $(BASHPID= EPOCHREALTIME= EXECSHELL= KSHEGID= KSHGID= KSHUID= KSH_MATCH= PATHSEP= PGRP= PIPESTATUS= TMPDIR= USER_ID= VPATH= CSWIDTH= complete)