diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-11-23 21:20:21 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-11-23 21:20:21 +0000 |
commit | 5bc593ccb8502703bd09a7cdc5a036fc748aa91e (patch) | |
tree | 5a2e3508fc5803e6b0eb64d17ec6d2678fa36801 | |
parent | cccdc4e01abb354c50aa483a21d5ff56a18c0b4a (diff) | |
download | busybox-w32-5bc593ccb8502703bd09a7cdc5a036fc748aa91e.tar.gz busybox-w32-5bc593ccb8502703bd09a7cdc5a036fc748aa91e.tar.bz2 busybox-w32-5bc593ccb8502703bd09a7cdc5a036fc748aa91e.zip |
hush: implement echo builtin
builtin_echo - 36 +36
bltins 384 396 +12
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/0 up/down: 48/0) Total: 48 bytes
-rw-r--r-- | shell/Config.in | 1 | ||||
-rw-r--r-- | shell/hush.c | 15 |
2 files changed, 16 insertions, 0 deletions
diff --git a/shell/Config.in b/shell/Config.in index 0689b4ec2..312583e87 100644 --- a/shell/Config.in +++ b/shell/Config.in | |||
@@ -166,6 +166,7 @@ config HUSH | |||
166 | select TRUE | 166 | select TRUE |
167 | select FALSE | 167 | select FALSE |
168 | select TEST | 168 | select TEST |
169 | select ECHO | ||
169 | help | 170 | help |
170 | hush is a very small shell (just 18k) and it has fairly complete | 171 | hush is a very small shell (just 18k) and it has fairly complete |
171 | Bourne shell grammar. It even handles all the normal flow control | 172 | Bourne shell grammar. It even handles all the normal flow control |
diff --git a/shell/hush.c b/shell/hush.c index 912cbb5d9..6bf4d1d19 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -614,6 +614,7 @@ static void free_strings(char **strings) | |||
614 | 614 | ||
615 | /* Function prototypes for builtins */ | 615 | /* Function prototypes for builtins */ |
616 | static int builtin_cd(char **argv); | 616 | static int builtin_cd(char **argv); |
617 | static int builtin_echo(char **argv); | ||
617 | static int builtin_eval(char **argv); | 618 | static int builtin_eval(char **argv); |
618 | static int builtin_exec(char **argv); | 619 | static int builtin_exec(char **argv); |
619 | static int builtin_exit(char **argv); | 620 | static int builtin_exit(char **argv); |
@@ -652,6 +653,8 @@ struct built_in_command { | |||
652 | #endif | 653 | #endif |
653 | }; | 654 | }; |
654 | 655 | ||
656 | /* For now, echo and test are unconditionally enabled. | ||
657 | * Maybe make it configurable? */ | ||
655 | static const struct built_in_command bltins[] = { | 658 | static const struct built_in_command bltins[] = { |
656 | BLTIN("[" , builtin_test, "Test condition"), | 659 | BLTIN("[" , builtin_test, "Test condition"), |
657 | BLTIN("[[" , builtin_test, "Test condition"), | 660 | BLTIN("[[" , builtin_test, "Test condition"), |
@@ -661,6 +664,7 @@ static const struct built_in_command bltins[] = { | |||
661 | // BLTIN("break" , builtin_not_written, "Exit for, while or until loop"), | 664 | // BLTIN("break" , builtin_not_written, "Exit for, while or until loop"), |
662 | BLTIN("cd" , builtin_cd, "Change working directory"), | 665 | BLTIN("cd" , builtin_cd, "Change working directory"), |
663 | // BLTIN("continue", builtin_not_written, "Continue for, while or until loop"), | 666 | // BLTIN("continue", builtin_not_written, "Continue for, while or until loop"), |
667 | BLTIN("echo" , builtin_echo, "Write strings to stdout"), | ||
664 | BLTIN("eval" , builtin_eval, "Construct and run shell command"), | 668 | BLTIN("eval" , builtin_eval, "Construct and run shell command"), |
665 | BLTIN("exec" , builtin_exec, "Exec command, replacing this shell with the exec'd process"), | 669 | BLTIN("exec" , builtin_exec, "Exec command, replacing this shell with the exec'd process"), |
666 | BLTIN("exit" , builtin_exit, "Exit from shell"), | 670 | BLTIN("exit" , builtin_exit, "Exit from shell"), |
@@ -841,6 +845,17 @@ static int builtin_test(char **argv) | |||
841 | return test_main(argc, argv - argc); | 845 | return test_main(argc, argv - argc); |
842 | } | 846 | } |
843 | 847 | ||
848 | /* built-in 'test' handler */ | ||
849 | static int builtin_echo(char **argv) | ||
850 | { | ||
851 | int argc = 0; | ||
852 | while (*argv) { | ||
853 | argc++; | ||
854 | argv++; | ||
855 | } | ||
856 | return bb_echo(argc, argv - argc); | ||
857 | } | ||
858 | |||
844 | /* built-in 'eval' handler */ | 859 | /* built-in 'eval' handler */ |
845 | static int builtin_eval(char **argv) | 860 | static int builtin_eval(char **argv) |
846 | { | 861 | { |