summaryrefslogtreecommitdiff
path: root/shell/hush.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2016-12-23 16:49:07 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2016-12-23 16:56:43 +0100
commit0b8835861b2e43cb45becdb560877bcc89aea827 (patch)
treeed8dedb7521a120702e8d17ebecfb68e2c5c1103 /shell/hush.c
parent04c1a2a2c4a5faaa1600ed0831c9a1be17dbdb3f (diff)
downloadbusybox-w32-0b8835861b2e43cb45becdb560877bcc89aea827.tar.gz
busybox-w32-0b8835861b2e43cb45becdb560877bcc89aea827.tar.bz2
busybox-w32-0b8835861b2e43cb45becdb560877bcc89aea827.zip
Make it possible to select "sh" and "bash" aliases without selecting ash or hush
The same can be done for msh, but we are probably better off just deleting it in a next versio or two. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell/hush.c')
-rw-r--r--shell/hush.c59
1 files changed, 24 insertions, 35 deletions
diff --git a/shell/hush.c b/shell/hush.c
index c5821259a..fecc89294 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -99,7 +99,7 @@
99//config:config HUSH_BASH_COMPAT 99//config:config HUSH_BASH_COMPAT
100//config: bool "bash-compatible extensions" 100//config: bool "bash-compatible extensions"
101//config: default y 101//config: default y
102//config: depends on HUSH 102//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH
103//config: help 103//config: help
104//config: Enable bash-compatible extensions. 104//config: Enable bash-compatible extensions.
105//config: 105//config:
@@ -113,14 +113,14 @@
113//config:config HUSH_HELP 113//config:config HUSH_HELP
114//config: bool "help builtin" 114//config: bool "help builtin"
115//config: default y 115//config: default y
116//config: depends on HUSH 116//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH
117//config: help 117//config: help
118//config: Enable help builtin in hush. Code size + ~1 kbyte. 118//config: Enable help builtin in hush. Code size + ~1 kbyte.
119//config: 119//config:
120//config:config HUSH_INTERACTIVE 120//config:config HUSH_INTERACTIVE
121//config: bool "Interactive mode" 121//config: bool "Interactive mode"
122//config: default y 122//config: default y
123//config: depends on HUSH 123//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH
124//config: help 124//config: help
125//config: Enable interactive mode (prompt and command editing). 125//config: Enable interactive mode (prompt and command editing).
126//config: Without this, hush simply reads and executes commands 126//config: Without this, hush simply reads and executes commands
@@ -148,35 +148,35 @@
148//config:config HUSH_TICK 148//config:config HUSH_TICK
149//config: bool "Process substitution" 149//config: bool "Process substitution"
150//config: default y 150//config: default y
151//config: depends on HUSH 151//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH
152//config: help 152//config: help
153//config: Enable process substitution `command` and $(command) in hush. 153//config: Enable process substitution `command` and $(command) in hush.
154//config: 154//config:
155//config:config HUSH_IF 155//config:config HUSH_IF
156//config: bool "Support if/then/elif/else/fi" 156//config: bool "Support if/then/elif/else/fi"
157//config: default y 157//config: default y
158//config: depends on HUSH 158//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH
159//config: help 159//config: help
160//config: Enable if/then/elif/else/fi in hush. 160//config: Enable if/then/elif/else/fi in hush.
161//config: 161//config:
162//config:config HUSH_LOOPS 162//config:config HUSH_LOOPS
163//config: bool "Support for, while and until loops" 163//config: bool "Support for, while and until loops"
164//config: default y 164//config: default y
165//config: depends on HUSH 165//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH
166//config: help 166//config: help
167//config: Enable for, while and until loops in hush. 167//config: Enable for, while and until loops in hush.
168//config: 168//config:
169//config:config HUSH_CASE 169//config:config HUSH_CASE
170//config: bool "Support case ... esac statement" 170//config: bool "Support case ... esac statement"
171//config: default y 171//config: default y
172//config: depends on HUSH 172//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH
173//config: help 173//config: help
174//config: Enable case ... esac statement in hush. +400 bytes. 174//config: Enable case ... esac statement in hush. +400 bytes.
175//config: 175//config:
176//config:config HUSH_FUNCTIONS 176//config:config HUSH_FUNCTIONS
177//config: bool "Support funcname() { commands; } syntax" 177//config: bool "Support funcname() { commands; } syntax"
178//config: default y 178//config: default y
179//config: depends on HUSH 179//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH
180//config: help 180//config: help
181//config: Enable support for shell functions in hush. +800 bytes. 181//config: Enable support for shell functions in hush. +800 bytes.
182//config: 182//config:
@@ -190,7 +190,7 @@
190//config:config HUSH_RANDOM_SUPPORT 190//config:config HUSH_RANDOM_SUPPORT
191//config: bool "Pseudorandom generator and $RANDOM variable" 191//config: bool "Pseudorandom generator and $RANDOM variable"
192//config: default y 192//config: default y
193//config: depends on HUSH 193//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH
194//config: help 194//config: help
195//config: Enable pseudorandom generator and dynamic variable "$RANDOM". 195//config: Enable pseudorandom generator and dynamic variable "$RANDOM".
196//config: Each read of "$RANDOM" will generate a new pseudorandom value. 196//config: Each read of "$RANDOM" will generate a new pseudorandom value.
@@ -198,14 +198,14 @@
198//config:config HUSH_EXPORT_N 198//config:config HUSH_EXPORT_N
199//config: bool "Support 'export -n' option" 199//config: bool "Support 'export -n' option"
200//config: default y 200//config: default y
201//config: depends on HUSH 201//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH
202//config: help 202//config: help
203//config: export -n unexports variables. It is a bash extension. 203//config: export -n unexports variables. It is a bash extension.
204//config: 204//config:
205//config:config HUSH_MODE_X 205//config:config HUSH_MODE_X
206//config: bool "Support 'hush -x' option and 'set -x' command" 206//config: bool "Support 'hush -x' option and 'set -x' command"
207//config: default y 207//config: default y
208//config: depends on HUSH 208//config: depends on HUSH || SH_IS_HUSH || BASH_IS_HUSH
209//config: help 209//config: help
210//config: This instructs hush to print commands before execution. 210//config: This instructs hush to print commands before execution.
211//config: Adds ~300 bytes. 211//config: Adds ~300 bytes.
@@ -216,14 +216,15 @@
216//config: select HUSH 216//config: select HUSH
217//config: help 217//config: help
218//config: msh is deprecated and will be removed, please migrate to hush. 218//config: msh is deprecated and will be removed, please migrate to hush.
219//config:
220 219
221//applet:IF_HUSH(APPLET(hush, BB_DIR_BIN, BB_SUID_DROP)) 220//applet:IF_HUSH(APPLET(hush, BB_DIR_BIN, BB_SUID_DROP))
222//applet:IF_MSH(APPLET(msh, BB_DIR_BIN, BB_SUID_DROP)) 221//applet:IF_MSH(APPLET_ODDNAME(msh, hush, BB_DIR_BIN, BB_SUID_DROP, hush))
223//applet:IF_FEATURE_SH_IS_HUSH(APPLET_ODDNAME(sh, hush, BB_DIR_BIN, BB_SUID_DROP, sh)) 222//applet:IF_SH_IS_HUSH(APPLET_ODDNAME(sh, hush, BB_DIR_BIN, BB_SUID_DROP, hush))
224//applet:IF_FEATURE_BASH_IS_HUSH(APPLET_ODDNAME(bash, hush, BB_DIR_BIN, BB_SUID_DROP, bash)) 223//applet:IF_BASH_IS_HUSH(APPLET_ODDNAME(bash, hush, BB_DIR_BIN, BB_SUID_DROP, hush))
225 224
226//kbuild:lib-$(CONFIG_HUSH) += hush.o match.o shell_common.o 225//kbuild:lib-$(CONFIG_HUSH) += hush.o match.o shell_common.o
226//kbuild:lib-$(CONFIG_SH_IS_HUSH) += hush.o match.o shell_common.o
227//kbuild:lib-$(CONFIG_BASH_IS_HUSH) += hush.o match.o shell_common.o
227//kbuild:lib-$(CONFIG_HUSH_RANDOM_SUPPORT) += random.o 228//kbuild:lib-$(CONFIG_HUSH_RANDOM_SUPPORT) += random.o
228 229
229/* -i (interactive) and -s (read stdin) are also accepted, 230/* -i (interactive) and -s (read stdin) are also accepted,
@@ -236,18 +237,6 @@
236//usage:#define hush_full_usage "\n\n" 237//usage:#define hush_full_usage "\n\n"
237//usage: "Unix shell interpreter" 238//usage: "Unix shell interpreter"
238 239
239//usage:#define msh_trivial_usage hush_trivial_usage
240//usage:#define msh_full_usage hush_full_usage
241
242//usage:#if ENABLE_FEATURE_SH_IS_HUSH
243//usage:# define sh_trivial_usage hush_trivial_usage
244//usage:# define sh_full_usage hush_full_usage
245//usage:#endif
246//usage:#if ENABLE_FEATURE_BASH_IS_HUSH
247//usage:# define bash_trivial_usage hush_trivial_usage
248//usage:# define bash_full_usage hush_full_usage
249//usage:#endif
250
251#if !(defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) \ 240#if !(defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) \
252 || defined(__APPLE__) \ 241 || defined(__APPLE__) \
253 ) 242 )
@@ -4011,7 +4000,7 @@ static int i_peek_and_eat_bkslash_nl(struct in_str *input)
4011 } 4000 }
4012} 4001}
4013 4002
4014#if ENABLE_HUSH_TICK || ENABLE_SH_MATH_SUPPORT || ENABLE_HUSH_DOLLAR_OPS 4003#if ENABLE_HUSH_TICK || ENABLE_FEATURE_SH_MATH || ENABLE_HUSH_DOLLAR_OPS
4015/* Subroutines for copying $(...) and `...` things */ 4004/* Subroutines for copying $(...) and `...` things */
4016static int add_till_backquote(o_string *dest, struct in_str *input, int in_dquote); 4005static int add_till_backquote(o_string *dest, struct in_str *input, int in_dquote);
4017/* '...' */ 4006/* '...' */
@@ -4179,7 +4168,7 @@ static int add_till_closing_bracket(o_string *dest, struct in_str *input, unsign
4179 } 4168 }
4180 return ch; 4169 return ch;
4181} 4170}
4182#endif /* ENABLE_HUSH_TICK || ENABLE_SH_MATH_SUPPORT || ENABLE_HUSH_DOLLAR_OPS */ 4171#endif /* ENABLE_HUSH_TICK || ENABLE_FEATURE_SH_MATH || ENABLE_HUSH_DOLLAR_OPS */
4183 4172
4184/* Return code: 0 for OK, 1 for syntax error */ 4173/* Return code: 0 for OK, 1 for syntax error */
4185#if BB_MMU 4174#if BB_MMU
@@ -4333,13 +4322,13 @@ static int parse_dollar(o_string *as_string,
4333 o_addchr(dest, SPECIAL_VAR_SYMBOL); 4322 o_addchr(dest, SPECIAL_VAR_SYMBOL);
4334 break; 4323 break;
4335 } 4324 }
4336#if ENABLE_SH_MATH_SUPPORT || ENABLE_HUSH_TICK 4325#if ENABLE_FEATURE_SH_MATH || ENABLE_HUSH_TICK
4337 case '(': { 4326 case '(': {
4338 unsigned pos; 4327 unsigned pos;
4339 4328
4340 ch = i_getch(input); 4329 ch = i_getch(input);
4341 nommu_addchr(as_string, ch); 4330 nommu_addchr(as_string, ch);
4342# if ENABLE_SH_MATH_SUPPORT 4331# if ENABLE_FEATURE_SH_MATH
4343 if (i_peek_and_eat_bkslash_nl(input) == '(') { 4332 if (i_peek_and_eat_bkslash_nl(input) == '(') {
4344 ch = i_getch(input); 4333 ch = i_getch(input);
4345 nommu_addchr(as_string, ch); 4334 nommu_addchr(as_string, ch);
@@ -5217,7 +5206,7 @@ static char *encode_then_expand_string(const char *str, int process_bkslash, int
5217 return exp_str; 5206 return exp_str;
5218} 5207}
5219 5208
5220#if ENABLE_SH_MATH_SUPPORT 5209#if ENABLE_FEATURE_SH_MATH
5221static arith_t expand_and_evaluate_arith(const char *arg, const char **errmsg_p) 5210static arith_t expand_and_evaluate_arith(const char *arg, const char **errmsg_p)
5222{ 5211{
5223 arith_state_t math_state; 5212 arith_state_t math_state;
@@ -5469,7 +5458,7 @@ static NOINLINE const char *expand_one_var(char **to_be_freed_pp, char *arg, cha
5469 } 5458 }
5470#endif 5459#endif
5471 else if (exp_op == ':') { 5460 else if (exp_op == ':') {
5472#if ENABLE_HUSH_BASH_COMPAT && ENABLE_SH_MATH_SUPPORT 5461#if ENABLE_HUSH_BASH_COMPAT && ENABLE_FEATURE_SH_MATH
5473 /* It's ${var:N[:M]} bashism. 5462 /* It's ${var:N[:M]} bashism.
5474 * Note that in encoded form it has TWO parts: 5463 * Note that in encoded form it has TWO parts:
5475 * var:N<SPECIAL_VAR_SYMBOL>M<SPECIAL_VAR_SYMBOL> 5464 * var:N<SPECIAL_VAR_SYMBOL>M<SPECIAL_VAR_SYMBOL>
@@ -5604,7 +5593,7 @@ static NOINLINE int expand_vars_to_list(o_string *output, int n, char *arg)
5604#if ENABLE_HUSH_TICK 5593#if ENABLE_HUSH_TICK
5605 o_string subst_result = NULL_O_STRING; 5594 o_string subst_result = NULL_O_STRING;
5606#endif 5595#endif
5607#if ENABLE_SH_MATH_SUPPORT 5596#if ENABLE_FEATURE_SH_MATH
5608 char arith_buf[sizeof(arith_t)*3 + 2]; 5597 char arith_buf[sizeof(arith_t)*3 + 2];
5609#endif 5598#endif
5610 5599
@@ -5698,7 +5687,7 @@ static NOINLINE int expand_vars_to_list(o_string *output, int n, char *arg)
5698 val = subst_result.data; 5687 val = subst_result.data;
5699 goto store_val; 5688 goto store_val;
5700#endif 5689#endif
5701#if ENABLE_SH_MATH_SUPPORT 5690#if ENABLE_FEATURE_SH_MATH
5702 case '+': { /* <SPECIAL_VAR_SYMBOL>+cmd<SPECIAL_VAR_SYMBOL> */ 5691 case '+': { /* <SPECIAL_VAR_SYMBOL>+cmd<SPECIAL_VAR_SYMBOL> */
5703 arith_t res; 5692 arith_t res;
5704 5693