hush: implement "hush -s"

function                                             old     new   delta
hush_main                                           1015    1031     +16
packed_usage                                       32757   32745     -12
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 16/-12)              Total: 4 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2018-04-05 16:46:49 +02:00
parent d878ccca9c
commit f2ed39b930
2 changed files with 9 additions and 9 deletions

View File

@ -13948,7 +13948,7 @@ init(void)
//usage:#define ash_trivial_usage //usage:#define ash_trivial_usage
//usage: "[-/+OPTIONS] [-/+o OPT]... [-c 'SCRIPT' [ARG0 [ARGS]] / FILE [ARGS]]" //usage: "[-/+OPTIONS] [-/+o OPT]... [-c 'SCRIPT' [ARG0 [ARGS]] / FILE [ARGS] / -s [ARGS]]"
//usage:#define ash_full_usage "\n\n" //usage:#define ash_full_usage "\n\n"
//usage: "Unix shell interpreter" //usage: "Unix shell interpreter"

View File

@ -312,13 +312,13 @@
//kbuild:lib-$(CONFIG_BASH_IS_HUSH) += hush.o match.o shell_common.o //kbuild:lib-$(CONFIG_BASH_IS_HUSH) += hush.o match.o shell_common.o
//kbuild:lib-$(CONFIG_HUSH_RANDOM_SUPPORT) += random.o //kbuild:lib-$(CONFIG_HUSH_RANDOM_SUPPORT) += random.o
/* -i (interactive) and -s (read stdin) are also accepted, /* -i (interactive) is also accepted,
* but currently do nothing, therefore aren't shown in help. * but does nothing, therefore not shown in help.
* NOMMU-specific options are not meant to be used by users, * NOMMU-specific options are not meant to be used by users,
* therefore we don't show them either. * therefore we don't show them either.
*/ */
//usage:#define hush_trivial_usage //usage:#define hush_trivial_usage
//usage: "[-enxl] [-c 'SCRIPT' [ARG0 [ARGS]] / FILE [ARGS]]" //usage: "[-enxl] [-c 'SCRIPT' [ARG0 [ARGS]] / FILE [ARGS] / -s [ARGS]]"
//usage:#define hush_full_usage "\n\n" //usage:#define hush_full_usage "\n\n"
//usage: "Unix shell interpreter" //usage: "Unix shell interpreter"
@ -9150,9 +9150,9 @@ int hush_main(int argc, char **argv)
{ {
enum { enum {
OPT_login = (1 << 0), OPT_login = (1 << 0),
OPT_s = (1 << 1),
}; };
unsigned flags; unsigned flags;
int opt;
unsigned builtin_argc; unsigned builtin_argc;
char **e; char **e;
struct variable *cur_var; struct variable *cur_var;
@ -9275,7 +9275,7 @@ int hush_main(int argc, char **argv)
flags = (argv[0] && argv[0][0] == '-') ? OPT_login : 0; flags = (argv[0] && argv[0][0] == '-') ? OPT_login : 0;
builtin_argc = 0; builtin_argc = 0;
while (1) { while (1) {
opt = getopt(argc, argv, "+c:exinsl" int opt = getopt(argc, argv, "+c:exinsl"
#if !BB_MMU #if !BB_MMU
"<:$:R:V:" "<:$:R:V:"
# if ENABLE_HUSH_FUNCTIONS # if ENABLE_HUSH_FUNCTIONS
@ -9333,8 +9333,7 @@ int hush_main(int argc, char **argv)
/* G_interactive_fd++; */ /* G_interactive_fd++; */
break; break;
case 's': case 's':
/* "-s" means "read from stdin", but this is how we always flags |= OPT_s;
* operate, so simply do nothing here. */
break; break;
case 'l': case 'l':
flags |= OPT_login; flags |= OPT_login;
@ -9437,7 +9436,8 @@ int hush_main(int argc, char **argv)
*/ */
} }
if (G.global_argv[1]) { /* -s is: hush -s ARGV1 ARGV2 (no SCRIPT) */
if (!(flags & OPT_s) && G.global_argv[1]) {
FILE *input; FILE *input;
/* /*
* "bash <script>" (which is never interactive (unless -i?)) * "bash <script>" (which is never interactive (unless -i?))