aboutsummaryrefslogtreecommitdiff
path: root/shell/hush.c
diff options
context:
space:
mode:
Diffstat (limited to 'shell/hush.c')
-rw-r--r--shell/hush.c75
1 files changed, 43 insertions, 32 deletions
diff --git a/shell/hush.c b/shell/hush.c
index cab7ea5b0..e9cec1cc9 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -95,6 +95,7 @@
95//config:config HUSH 95//config:config HUSH
96//config: bool "hush (68 kb)" 96//config: bool "hush (68 kb)"
97//config: default y 97//config: default y
98//config: select SHELL_HUSH
98//config: help 99//config: help
99//config: hush is a small shell. It handles the normal flow control 100//config: hush is a small shell. It handles the normal flow control
100//config: constructs such as if/then/elif/else/fi, for/in/do/done, while loops, 101//config: constructs such as if/then/elif/else/fi, for/in/do/done, while loops,
@@ -106,10 +107,20 @@
106//config: It does not handle select, aliases, tilde expansion, 107//config: It does not handle select, aliases, tilde expansion,
107//config: &>file and >&file redirection of stdout+stderr. 108//config: &>file and >&file redirection of stdout+stderr.
108//config: 109//config:
110// This option is visible (has a description) to make it possible to select
111// a "scripted" applet (such as NOLOGIN) but avoid selecting any shells:
112//config:config SHELL_HUSH
113//config: bool "Internal shell for embedded script support"
114//config: default n
115//config:
116//config:# hush options
117//config:# It's only needed to get "nice" menuconfig indenting.
118//config:if SHELL_HUSH || HUSH || SH_IS_HUSH || BASH_IS_HUSH
119//config:
109//config:config HUSH_BASH_COMPAT 120//config:config HUSH_BASH_COMPAT
110//config: bool "bash-compatible extensions" 121//config: bool "bash-compatible extensions"
111//config: default y 122//config: default y
112//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH 123//config: depends on SHELL_HUSH
113//config: 124//config:
114//config:config HUSH_BRACE_EXPANSION 125//config:config HUSH_BRACE_EXPANSION
115//config: bool "Brace expansion" 126//config: bool "Brace expansion"
@@ -133,7 +144,7 @@
133//config:config HUSH_INTERACTIVE 144//config:config HUSH_INTERACTIVE
134//config: bool "Interactive mode" 145//config: bool "Interactive mode"
135//config: default y 146//config: default y
136//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH 147//config: depends on SHELL_HUSH
137//config: help 148//config: help
138//config: Enable interactive mode (prompt and command editing). 149//config: Enable interactive mode (prompt and command editing).
139//config: Without this, hush simply reads and executes commands 150//config: Without this, hush simply reads and executes commands
@@ -159,31 +170,31 @@
159//config:config HUSH_TICK 170//config:config HUSH_TICK
160//config: bool "Support command substitution" 171//config: bool "Support command substitution"
161//config: default y 172//config: default y
162//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH 173//config: depends on SHELL_HUSH
163//config: help 174//config: help
164//config: Enable `command` and $(command). 175//config: Enable `command` and $(command).
165//config: 176//config:
166//config:config HUSH_IF 177//config:config HUSH_IF
167//config: bool "Support if/then/elif/else/fi" 178//config: bool "Support if/then/elif/else/fi"
168//config: default y 179//config: default y
169//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH 180//config: depends on SHELL_HUSH
170//config: 181//config:
171//config:config HUSH_LOOPS 182//config:config HUSH_LOOPS
172//config: bool "Support for, while and until loops" 183//config: bool "Support for, while and until loops"
173//config: default y 184//config: default y
174//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH 185//config: depends on SHELL_HUSH
175//config: 186//config:
176//config:config HUSH_CASE 187//config:config HUSH_CASE
177//config: bool "Support case ... esac statement" 188//config: bool "Support case ... esac statement"
178//config: default y 189//config: default y
179//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH 190//config: depends on SHELL_HUSH
180//config: help 191//config: help
181//config: Enable case ... esac statement. +400 bytes. 192//config: Enable case ... esac statement. +400 bytes.
182//config: 193//config:
183//config:config HUSH_FUNCTIONS 194//config:config HUSH_FUNCTIONS
184//config: bool "Support funcname() { commands; } syntax" 195//config: bool "Support funcname() { commands; } syntax"
185//config: default y 196//config: default y
186//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH 197//config: depends on SHELL_HUSH
187//config: help 198//config: help
188//config: Enable support for shell functions. +800 bytes. 199//config: Enable support for shell functions. +800 bytes.
189//config: 200//config:
@@ -197,7 +208,7 @@
197//config:config HUSH_RANDOM_SUPPORT 208//config:config HUSH_RANDOM_SUPPORT
198//config: bool "Pseudorandom generator and $RANDOM variable" 209//config: bool "Pseudorandom generator and $RANDOM variable"
199//config: default y 210//config: default y
200//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH 211//config: depends on SHELL_HUSH
201//config: help 212//config: help
202//config: Enable pseudorandom generator and dynamic variable "$RANDOM". 213//config: Enable pseudorandom generator and dynamic variable "$RANDOM".
203//config: Each read of "$RANDOM" will generate a new pseudorandom value. 214//config: Each read of "$RANDOM" will generate a new pseudorandom value.
@@ -205,7 +216,7 @@
205//config:config HUSH_MODE_X 216//config:config HUSH_MODE_X
206//config: bool "Support 'hush -x' option and 'set -x' command" 217//config: bool "Support 'hush -x' option and 'set -x' command"
207//config: default y 218//config: default y
208//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH 219//config: depends on SHELL_HUSH
209//config: help 220//config: help
210//config: This instructs hush to print commands before execution. 221//config: This instructs hush to print commands before execution.
211//config: Adds ~300 bytes. 222//config: Adds ~300 bytes.
@@ -213,27 +224,27 @@
213//config:config HUSH_ECHO 224//config:config HUSH_ECHO
214//config: bool "echo builtin" 225//config: bool "echo builtin"
215//config: default y 226//config: default y
216//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH 227//config: depends on SHELL_HUSH
217//config: 228//config:
218//config:config HUSH_PRINTF 229//config:config HUSH_PRINTF
219//config: bool "printf builtin" 230//config: bool "printf builtin"
220//config: default y 231//config: default y
221//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH 232//config: depends on SHELL_HUSH
222//config: 233//config:
223//config:config HUSH_TEST 234//config:config HUSH_TEST
224//config: bool "test builtin" 235//config: bool "test builtin"
225//config: default y 236//config: default y
226//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH 237//config: depends on SHELL_HUSH
227//config: 238//config:
228//config:config HUSH_HELP 239//config:config HUSH_HELP
229//config: bool "help builtin" 240//config: bool "help builtin"
230//config: default y 241//config: default y
231//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH 242//config: depends on SHELL_HUSH
232//config: 243//config:
233//config:config HUSH_EXPORT 244//config:config HUSH_EXPORT
234//config: bool "export builtin" 245//config: bool "export builtin"
235//config: default y 246//config: default y
236//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH 247//config: depends on SHELL_HUSH
237//config: 248//config:
238//config:config HUSH_EXPORT_N 249//config:config HUSH_EXPORT_N
239//config: bool "Support 'export -n' option" 250//config: bool "Support 'export -n' option"
@@ -245,83 +256,83 @@
245//config:config HUSH_READONLY 256//config:config HUSH_READONLY
246//config: bool "readonly builtin" 257//config: bool "readonly builtin"
247//config: default y 258//config: default y
248//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH 259//config: depends on SHELL_HUSH
249//config: help 260//config: help
250//config: Enable support for read-only variables. 261//config: Enable support for read-only variables.
251//config: 262//config:
252//config:config HUSH_KILL 263//config:config HUSH_KILL
253//config: bool "kill builtin (supports kill %jobspec)" 264//config: bool "kill builtin (supports kill %jobspec)"
254//config: default y 265//config: default y
255//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH 266//config: depends on SHELL_HUSH
256//config: 267//config:
257//config:config HUSH_WAIT 268//config:config HUSH_WAIT
258//config: bool "wait builtin" 269//config: bool "wait builtin"
259//config: default y 270//config: default y
260//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH 271//config: depends on SHELL_HUSH
261//config: 272//config:
262//config:config HUSH_COMMAND 273//config:config HUSH_COMMAND
263//config: bool "command builtin" 274//config: bool "command builtin"
264//config: default y 275//config: default y
265//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH 276//config: depends on SHELL_HUSH
266//config: 277//config:
267//config:config HUSH_TRAP 278//config:config HUSH_TRAP
268//config: bool "trap builtin" 279//config: bool "trap builtin"
269//config: default y 280//config: default y
270//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH 281//config: depends on SHELL_HUSH
271//config: 282//config:
272//config:config HUSH_TYPE 283//config:config HUSH_TYPE
273//config: bool "type builtin" 284//config: bool "type builtin"
274//config: default y 285//config: default y
275//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH 286//config: depends on SHELL_HUSH
276//config: 287//config:
277//config:config HUSH_TIMES 288//config:config HUSH_TIMES
278//config: bool "times builtin" 289//config: bool "times builtin"
279//config: default y 290//config: default y
280//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH 291//config: depends on SHELL_HUSH
281//config: 292//config:
282//config:config HUSH_READ 293//config:config HUSH_READ
283//config: bool "read builtin" 294//config: bool "read builtin"
284//config: default y 295//config: default y
285//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH 296//config: depends on SHELL_HUSH
286//config: 297//config:
287//config:config HUSH_SET 298//config:config HUSH_SET
288//config: bool "set builtin" 299//config: bool "set builtin"
289//config: default y 300//config: default y
290//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH 301//config: depends on SHELL_HUSH
291//config: 302//config:
292//config:config HUSH_UNSET 303//config:config HUSH_UNSET
293//config: bool "unset builtin" 304//config: bool "unset builtin"
294//config: default y 305//config: default y
295//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH 306//config: depends on SHELL_HUSH
296//config: 307//config:
297//config:config HUSH_ULIMIT 308//config:config HUSH_ULIMIT
298//config: bool "ulimit builtin" 309//config: bool "ulimit builtin"
299//config: default y 310//config: default y
300//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH 311//config: depends on SHELL_HUSH
301//config: 312//config:
302//config:config HUSH_UMASK 313//config:config HUSH_UMASK
303//config: bool "umask builtin" 314//config: bool "umask builtin"
304//config: default y 315//config: default y
305//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH 316//config: depends on SHELL_HUSH
306//config: 317//config:
307//config:config HUSH_GETOPTS 318//config:config HUSH_GETOPTS
308//config: bool "getopts builtin" 319//config: bool "getopts builtin"
309//config: default y 320//config: default y
310//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH 321//config: depends on SHELL_HUSH
311//config: 322//config:
312//config:config HUSH_MEMLEAK 323//config:config HUSH_MEMLEAK
313//config: bool "memleak builtin (debugging)" 324//config: bool "memleak builtin (debugging)"
314//config: default n 325//config: default n
315//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH 326//config: depends on SHELL_HUSH
327//config:
328//config:endif # hush options
316 329
317//applet:IF_HUSH(APPLET(hush, BB_DIR_BIN, BB_SUID_DROP)) 330//applet:IF_HUSH(APPLET(hush, BB_DIR_BIN, BB_SUID_DROP))
318// APPLET_ODDNAME:name main location suid_type help 331// APPLET_ODDNAME:name main location suid_type help
319//applet:IF_SH_IS_HUSH( APPLET_ODDNAME(sh, hush, BB_DIR_BIN, BB_SUID_DROP, hush)) 332//applet:IF_SH_IS_HUSH( APPLET_ODDNAME(sh, hush, BB_DIR_BIN, BB_SUID_DROP, hush))
320//applet:IF_BASH_IS_HUSH(APPLET_ODDNAME(bash, hush, BB_DIR_BIN, BB_SUID_DROP, hush)) 333//applet:IF_BASH_IS_HUSH(APPLET_ODDNAME(bash, hush, BB_DIR_BIN, BB_SUID_DROP, hush))
321 334
322//kbuild:lib-$(CONFIG_HUSH) += hush.o match.o shell_common.o 335//kbuild:lib-$(CONFIG_SHELL_HUSH) += hush.o match.o shell_common.o
323//kbuild:lib-$(CONFIG_SH_IS_HUSH) += hush.o match.o shell_common.o
324//kbuild:lib-$(CONFIG_BASH_IS_HUSH) += hush.o match.o shell_common.o
325//kbuild:lib-$(CONFIG_HUSH_RANDOM_SUPPORT) += random.o 336//kbuild:lib-$(CONFIG_HUSH_RANDOM_SUPPORT) += random.o
326 337
327/* -i (interactive) is also accepted, 338/* -i (interactive) is also accepted,
@@ -7917,7 +7928,7 @@ static const struct built_in_command *find_builtin(const char *name)
7917 return find_builtin_helper(name, bltins2, &bltins2[ARRAY_SIZE(bltins2)]); 7928 return find_builtin_helper(name, bltins2, &bltins2[ARRAY_SIZE(bltins2)]);
7918} 7929}
7919 7930
7920#if EDITING_HAS_get_exe_name 7931#if ENABLE_HUSH_JOB && EDITING_HAS_get_exe_name
7921static const char * FAST_FUNC get_builtin_name(int i) 7932static const char * FAST_FUNC get_builtin_name(int i)
7922{ 7933{
7923 if (/*i >= 0 && */ i < ARRAY_SIZE(bltins1)) { 7934 if (/*i >= 0 && */ i < ARRAY_SIZE(bltins1)) {