diff options
author | Eric Andersen <andersen@codepoet.org> | 2001-07-07 00:05:55 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2001-07-07 00:05:55 +0000 |
commit | 1c03923b0b50d710cf78d02cf2a2fc80090455ef (patch) | |
tree | 1089bdbb9d8a20b986300ba598f3e639e6a848ec /shell | |
parent | b7e6f13b3c264f6d689f0eefc61d4718c3043062 (diff) | |
download | busybox-w32-1c03923b0b50d710cf78d02cf2a2fc80090455ef.tar.gz busybox-w32-1c03923b0b50d710cf78d02cf2a2fc80090455ef.tar.bz2 busybox-w32-1c03923b0b50d710cf78d02cf2a2fc80090455ef.zip |
Add in a shell tagline (per lash/hush behavior) to make it easier
to know which shell is in use. Add in 'help' to list available
builtins, and fixup msh so it can do STANDALONE_SHELL.
-Erik
Diffstat (limited to 'shell')
-rw-r--r-- | shell/ash.c | 61 | ||||
-rw-r--r-- | shell/msh.c | 128 |
2 files changed, 158 insertions, 31 deletions
diff --git a/shell/ash.c b/shell/ash.c index 99460d3d6..4250f50e2 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -1603,6 +1603,7 @@ static int exitcmd (int, char **); | |||
1603 | static int exportcmd (int, char **); | 1603 | static int exportcmd (int, char **); |
1604 | static int histcmd (int, char **); | 1604 | static int histcmd (int, char **); |
1605 | static int hashcmd (int, char **); | 1605 | static int hashcmd (int, char **); |
1606 | static int helpcmd (int, char **); | ||
1606 | static int jobscmd (int, char **); | 1607 | static int jobscmd (int, char **); |
1607 | static int localcmd (int, char **); | 1608 | static int localcmd (int, char **); |
1608 | #ifndef BB_PWD | 1609 | #ifndef BB_PWD |
@@ -1704,6 +1705,7 @@ static const struct builtincmd builtincmds[] = { | |||
1704 | { BUILTIN_REGULAR "getopts", getoptscmd }, | 1705 | { BUILTIN_REGULAR "getopts", getoptscmd }, |
1705 | #endif | 1706 | #endif |
1706 | { BUILTIN_NOSPEC "hash", hashcmd }, | 1707 | { BUILTIN_NOSPEC "hash", hashcmd }, |
1708 | { BUILTIN_NOSPEC "help", helpcmd }, | ||
1707 | { BUILTIN_REGULAR "jobs", jobscmd }, | 1709 | { BUILTIN_REGULAR "jobs", jobscmd }, |
1708 | #ifdef JOBS | 1710 | #ifdef JOBS |
1709 | { BUILTIN_REGULAR "kill", killcmd }, | 1711 | { BUILTIN_REGULAR "kill", killcmd }, |
@@ -3274,6 +3276,7 @@ static void | |||
3274 | setinteractive(int on) | 3276 | setinteractive(int on) |
3275 | { | 3277 | { |
3276 | static int is_interactive; | 3278 | static int is_interactive; |
3279 | static int do_banner=0; | ||
3277 | 3280 | ||
3278 | if (on == is_interactive) | 3281 | if (on == is_interactive) |
3279 | return; | 3282 | return; |
@@ -3282,6 +3285,12 @@ setinteractive(int on) | |||
3282 | setsignal(SIGTERM); | 3285 | setsignal(SIGTERM); |
3283 | chkmail(1); | 3286 | chkmail(1); |
3284 | is_interactive = on; | 3287 | is_interactive = on; |
3288 | if (do_banner==0 && is_interactive) { | ||
3289 | /* Looks like they want an interactive shell */ | ||
3290 | printf( "\n\n" BB_BANNER " Built-in shell (ash)\n"); | ||
3291 | printf( "Enter 'help' for a list of built-in commands.\n\n"); | ||
3292 | do_banner=1; | ||
3293 | } | ||
3285 | } | 3294 | } |
3286 | 3295 | ||
3287 | static void | 3296 | static void |
@@ -3802,6 +3811,51 @@ printentry(cmdp, verbose) | |||
3802 | 3811 | ||
3803 | 3812 | ||
3804 | 3813 | ||
3814 | /*** List the available builtins ***/ | ||
3815 | |||
3816 | |||
3817 | static int helpcmd(int argc, char** argv) | ||
3818 | { | ||
3819 | int col, i; | ||
3820 | const struct builtincmd *x; | ||
3821 | |||
3822 | printf("\nBuilt-in commands:\n"); | ||
3823 | printf("-------------------\n"); | ||
3824 | for (col=0, i=0, x = builtincmds; i < NUMBUILTINS; x++, i++) { | ||
3825 | if (!x->name || ! (x->name+1)) | ||
3826 | continue; | ||
3827 | col += printf("%s%s", ((col == 0) ? "\t" : " "), | ||
3828 | (x->name+1)); | ||
3829 | if (col > 60) { | ||
3830 | printf("\n"); | ||
3831 | col = 0; | ||
3832 | } | ||
3833 | } | ||
3834 | #ifdef BB_FEATURE_SH_STANDALONE_SHELL | ||
3835 | { | ||
3836 | const struct BB_applet *applet; | ||
3837 | extern const struct BB_applet applets[]; | ||
3838 | extern const size_t NUM_APPLETS; | ||
3839 | |||
3840 | for (i=0, applet = applets; i < NUM_APPLETS; applet++, i++) { | ||
3841 | if (!applet->name) | ||
3842 | continue; | ||
3843 | |||
3844 | col += printf("%s%s", ((col == 0) ? "\t" : " "), | ||
3845 | applet->name); | ||
3846 | if (col > 60) { | ||
3847 | printf("\n"); | ||
3848 | col = 0; | ||
3849 | } | ||
3850 | } | ||
3851 | } | ||
3852 | #endif | ||
3853 | printf("\n\n"); | ||
3854 | return EXIT_SUCCESS; | ||
3855 | } | ||
3856 | |||
3857 | |||
3858 | |||
3805 | /* | 3859 | /* |
3806 | * Resolve a command name. If you change this routine, you may have to | 3860 | * Resolve a command name. If you change this routine, you may have to |
3807 | * change the shellexec routine as well. | 3861 | * change the shellexec routine as well. |
@@ -7755,6 +7809,11 @@ shell_main(argc, argv) | |||
7755 | EXECCMD = find_builtin("exec"); | 7809 | EXECCMD = find_builtin("exec"); |
7756 | EVALCMD = find_builtin("eval"); | 7810 | EVALCMD = find_builtin("eval"); |
7757 | 7811 | ||
7812 | #ifndef BB_FEATURE_SH_FANCY_PROMPT | ||
7813 | unsetenv("PS1"); | ||
7814 | unsetenv("PS2"); | ||
7815 | #endif | ||
7816 | |||
7758 | #if PROFILE | 7817 | #if PROFILE |
7759 | monitor(4, etext, profile_buf, sizeof profile_buf, 50); | 7818 | monitor(4, etext, profile_buf, sizeof profile_buf, 50); |
7760 | #endif | 7819 | #endif |
@@ -13088,7 +13147,7 @@ findvar(struct var **vpp, const char *name) | |||
13088 | /* | 13147 | /* |
13089 | * Copyright (c) 1999 Herbert Xu <herbert@debian.org> | 13148 | * Copyright (c) 1999 Herbert Xu <herbert@debian.org> |
13090 | * This file contains code for the times builtin. | 13149 | * This file contains code for the times builtin. |
13091 | * $Id: ash.c,v 1.6 2001/07/06 04:26:23 andersen Exp $ | 13150 | * $Id: ash.c,v 1.7 2001/07/07 00:05:55 andersen Exp $ |
13092 | */ | 13151 | */ |
13093 | static int timescmd (int argc, char **argv) | 13152 | static int timescmd (int argc, char **argv) |
13094 | { | 13153 | { |
diff --git a/shell/msh.c b/shell/msh.c index 66c3d54d3..e85d6ff8f 100644 --- a/shell/msh.c +++ b/shell/msh.c | |||
@@ -497,6 +497,7 @@ static struct op **find1case (struct op *t, char *w ); | |||
497 | static struct op *findcase (struct op *t, char *w ); | 497 | static struct op *findcase (struct op *t, char *w ); |
498 | static void brkset(struct brkcon *bc ); | 498 | static void brkset(struct brkcon *bc ); |
499 | static int dolabel(void); | 499 | static int dolabel(void); |
500 | static int dohelp(void); | ||
500 | static int dochdir(struct op *t ); | 501 | static int dochdir(struct op *t ); |
501 | static int doshift(struct op *t ); | 502 | static int doshift(struct op *t ); |
502 | static int dologin(struct op *t ); | 503 | static int dologin(struct op *t ); |
@@ -592,30 +593,31 @@ static struct res restab[] = { | |||
592 | }; | 593 | }; |
593 | 594 | ||
594 | 595 | ||
595 | struct builtin { | 596 | struct builtincmd { |
596 | char *command; | 597 | const char *name; |
597 | int (*fn)(); | 598 | int (*builtinfunc)(); |
598 | }; | 599 | }; |
599 | static struct builtin builtin[] = { | 600 | static const struct builtincmd builtincmds[] = { |
601 | {".", dodot}, | ||
600 | {":", dolabel}, | 602 | {":", dolabel}, |
601 | {"cd", dochdir}, | ||
602 | {"shift", doshift}, | ||
603 | {"exec", doexec}, | ||
604 | {"wait", dowait}, | ||
605 | {"read", doread}, | ||
606 | {"eval", doeval}, | ||
607 | {"trap", dotrap}, | ||
608 | {"break", dobreak}, | 603 | {"break", dobreak}, |
604 | {"cd", dochdir}, | ||
609 | {"continue",docontinue}, | 605 | {"continue",docontinue}, |
606 | {"eval", doeval}, | ||
607 | {"exec", doexec}, | ||
610 | {"exit", doexit}, | 608 | {"exit", doexit}, |
611 | {"export", doexport}, | 609 | {"export", doexport}, |
612 | {"readonly",doreadonly}, | 610 | {"help", dohelp}, |
613 | {"set", doset}, | ||
614 | {".", dodot}, | ||
615 | {"umask", doumask}, | ||
616 | {"login", dologin}, | 611 | {"login", dologin}, |
617 | {"newgrp", dologin}, | 612 | {"newgrp", dologin}, |
613 | {"read", doread}, | ||
614 | {"readonly",doreadonly}, | ||
615 | {"set", doset}, | ||
616 | {"shift", doshift}, | ||
618 | {"times", dotimes}, | 617 | {"times", dotimes}, |
618 | {"trap", dotrap}, | ||
619 | {"umask", doumask}, | ||
620 | {"wait", dowait}, | ||
619 | {0,0} | 621 | {0,0} |
620 | }; | 622 | }; |
621 | 623 | ||
@@ -731,14 +733,18 @@ extern int shell_main(int argc, char **argv) | |||
731 | setval(ifs, " \t\n"); | 733 | setval(ifs, " \t\n"); |
732 | 734 | ||
733 | prompt = lookup("PS1"); | 735 | prompt = lookup("PS1"); |
736 | #ifdef BB_FEATURE_SH_FANCY_PROMPT | ||
734 | if (prompt->value == null) | 737 | if (prompt->value == null) |
738 | #endif | ||
735 | setval(prompt, "$ "); | 739 | setval(prompt, "$ "); |
736 | if (geteuid() == 0) { | 740 | if (geteuid() == 0) { |
737 | setval(prompt, "# "); | 741 | setval(prompt, "# "); |
738 | prompt->status &= ~EXPORT; | 742 | prompt->status &= ~EXPORT; |
739 | } | 743 | } |
740 | cprompt = lookup("PS2"); | 744 | cprompt = lookup("PS2"); |
745 | #ifdef BB_FEATURE_SH_FANCY_PROMPT | ||
741 | if (cprompt->value == null) | 746 | if (cprompt->value == null) |
747 | #endif | ||
742 | setval(cprompt, "> "); | 748 | setval(cprompt, "> "); |
743 | 749 | ||
744 | iof = filechar; | 750 | iof = filechar; |
@@ -794,8 +800,11 @@ extern int shell_main(int argc, char **argv) | |||
794 | setdash(); | 800 | setdash(); |
795 | if (e.iop < iostack) { | 801 | if (e.iop < iostack) { |
796 | PUSHIO(afile, 0, iof); | 802 | PUSHIO(afile, 0, iof); |
797 | if (isatty(0) && isatty(1) && !cflag) | 803 | if (isatty(0) && isatty(1) && !cflag) { |
798 | interactive++; | 804 | interactive++; |
805 | printf( "\n\n" BB_BANNER " Built-in shell (msh)\n"); | ||
806 | printf( "Enter 'help' for a list of built-in commands.\n\n"); | ||
807 | } | ||
799 | } | 808 | } |
800 | signal(SIGQUIT, qflag); | 809 | signal(SIGQUIT, qflag); |
801 | if (name && name[0] == '-') { | 810 | if (name && name[0] == '-') { |
@@ -2314,14 +2323,14 @@ int act; | |||
2314 | switch(t->type) { | 2323 | switch(t->type) { |
2315 | case TPAREN: | 2324 | case TPAREN: |
2316 | case TCOM: | 2325 | case TCOM: |
2317 | { | 2326 | { |
2318 | int child; | 2327 | int child; |
2319 | rv = forkexec(t, pin, pout, act, wp, &child); | 2328 | rv = forkexec(t, pin, pout, act, wp, &child); |
2320 | if (child) { | 2329 | if (child) { |
2321 | exstat = rv; | 2330 | exstat = rv; |
2322 | leave(); | 2331 | leave(); |
2332 | } | ||
2323 | } | 2333 | } |
2324 | } | ||
2325 | break; | 2334 | break; |
2326 | 2335 | ||
2327 | case TPIPE: | 2336 | case TPIPE: |
@@ -2828,6 +2837,21 @@ char *c, **v, **envp; | |||
2828 | register char *sp, *tp; | 2837 | register char *sp, *tp; |
2829 | int eacces = 0, asis = 0; | 2838 | int eacces = 0, asis = 0; |
2830 | 2839 | ||
2840 | #ifdef BB_FEATURE_SH_STANDALONE_SHELL | ||
2841 | char *name = c; | ||
2842 | #ifdef BB_FEATURE_SH_APPLETS_ALWAYS_WIN | ||
2843 | name = get_last_path_component(name); | ||
2844 | #endif | ||
2845 | optind = 1; | ||
2846 | if (find_applet_by_name(name)) { | ||
2847 | /* We have to exec here since we vforked. Running | ||
2848 | * run_applet_by_name() won't work and bad things | ||
2849 | * will happen. */ | ||
2850 | execve("/proc/self/exe", v, envp); | ||
2851 | execve("busybox", v, envp); | ||
2852 | } | ||
2853 | #endif | ||
2854 | |||
2831 | sp = any('/', c)? "": path->value; | 2855 | sp = any('/', c)? "": path->value; |
2832 | asis = *sp == '\0'; | 2856 | asis = *sp == '\0'; |
2833 | while (asis || *sp != '\0') { | 2857 | while (asis || *sp != '\0') { |
@@ -2842,6 +2866,8 @@ char *c, **v, **envp; | |||
2842 | *tp++ = '/'; | 2866 | *tp++ = '/'; |
2843 | for (i = 0; (*tp++ = c[i++]) != '\0';) | 2867 | for (i = 0; (*tp++ = c[i++]) != '\0';) |
2844 | ; | 2868 | ; |
2869 | |||
2870 | fprintf(stderr, "calling exec\n"); | ||
2845 | execve(e.linep, v, envp); | 2871 | execve(e.linep, v, envp); |
2846 | switch (errno) { | 2872 | switch (errno) { |
2847 | case ENOEXEC: | 2873 | case ENOEXEC: |
@@ -2917,6 +2943,49 @@ int (*f)(); | |||
2917 | * built-in commands: doX | 2943 | * built-in commands: doX |
2918 | */ | 2944 | */ |
2919 | 2945 | ||
2946 | static int dohelp() | ||
2947 | { | ||
2948 | int col; | ||
2949 | const struct builtincmd *x; | ||
2950 | |||
2951 | printf("\nBuilt-in commands:\n"); | ||
2952 | printf("-------------------\n"); | ||
2953 | |||
2954 | for (col=0, x = builtincmds; x->builtinfunc != NULL; x++) { | ||
2955 | if (!x->name) | ||
2956 | continue; | ||
2957 | col += printf("%s%s", ((col == 0) ? "\t" : " "), x->name); | ||
2958 | if (col > 60) { | ||
2959 | printf("\n"); | ||
2960 | col = 0; | ||
2961 | } | ||
2962 | } | ||
2963 | #ifdef BB_FEATURE_SH_STANDALONE_SHELL | ||
2964 | { | ||
2965 | int i; | ||
2966 | const struct BB_applet *applet; | ||
2967 | extern const struct BB_applet applets[]; | ||
2968 | extern const size_t NUM_APPLETS; | ||
2969 | |||
2970 | for (i=0, applet = applets; i < NUM_APPLETS; applet++, i++) { | ||
2971 | if (!applet->name) | ||
2972 | continue; | ||
2973 | |||
2974 | col += printf("%s%s", ((col == 0) ? "\t" : " "), | ||
2975 | applet->name); | ||
2976 | if (col > 60) { | ||
2977 | printf("\n"); | ||
2978 | col = 0; | ||
2979 | } | ||
2980 | } | ||
2981 | } | ||
2982 | #endif | ||
2983 | printf("\n\n"); | ||
2984 | return EXIT_SUCCESS; | ||
2985 | } | ||
2986 | |||
2987 | |||
2988 | |||
2920 | static int | 2989 | static int |
2921 | dolabel() | 2990 | dolabel() |
2922 | { | 2991 | { |
@@ -3341,7 +3410,6 @@ int out; | |||
3341 | /* | 3410 | /* |
3342 | * Copyright (c) 1999 Herbert Xu <herbert@debian.org> | 3411 | * Copyright (c) 1999 Herbert Xu <herbert@debian.org> |
3343 | * This file contains code for the times builtin. | 3412 | * This file contains code for the times builtin. |
3344 | * $Id: msh.c,v 1.1 2001/06/29 04:57:14 andersen Exp $ | ||
3345 | */ | 3413 | */ |
3346 | static int dotimes () | 3414 | static int dotimes () |
3347 | { | 3415 | { |
@@ -3362,14 +3430,14 @@ static int dotimes () | |||
3362 | } | 3430 | } |
3363 | 3431 | ||
3364 | 3432 | ||
3365 | static int (*inbuilt(s))() | 3433 | static int (*inbuilt(char *s))() |
3366 | register char *s; | ||
3367 | { | 3434 | { |
3368 | register struct builtin *bp; | 3435 | const struct builtincmd *bp; |
3436 | |||
3437 | for (bp = builtincmds; bp->name != NULL; bp++) | ||
3438 | if (strcmp(bp->name, s) == 0) | ||
3439 | return(bp->builtinfunc); | ||
3369 | 3440 | ||
3370 | for (bp = builtin; bp->command != NULL; bp++) | ||
3371 | if (strcmp(bp->command, s) == 0) | ||
3372 | return(bp->fn); | ||
3373 | return((int(*)())NULL); | 3441 | return((int(*)())NULL); |
3374 | } | 3442 | } |
3375 | 3443 | ||