aboutsummaryrefslogtreecommitdiff
path: root/sh.c
diff options
context:
space:
mode:
Diffstat (limited to 'sh.c')
-rw-r--r--sh.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/sh.c b/sh.c
index 9d4c27a9a..8ea5e305b 100644
--- a/sh.c
+++ b/sh.c
@@ -113,13 +113,18 @@ static int busy_loop(FILE * input);
113static struct builtInCommand bltins[] = { 113static struct builtInCommand bltins[] = {
114 {"bg", "Resume a job in the background", "bg [%%job]", shell_fg_bg}, 114 {"bg", "Resume a job in the background", "bg [%%job]", shell_fg_bg},
115 {"cd", "Change working directory", "cd [dir]", shell_cd}, 115 {"cd", "Change working directory", "cd [dir]", shell_cd},
116 {"env", "Print all environment variables", "env", shell_env},
117 {"exit", "Exit from shell()", "exit", shell_exit}, 116 {"exit", "Exit from shell()", "exit", shell_exit},
118 {"fg", "Bring job into the foreground", "fg [%%job]", shell_fg_bg}, 117 {"fg", "Bring job into the foreground", "fg [%%job]", shell_fg_bg},
119 {"jobs", "Lists the active jobs", "jobs", shell_jobs}, 118 {"jobs", "Lists the active jobs", "jobs", shell_jobs},
120 {"pwd", "Print current directory", "pwd", shell_pwd},
121 {"export", "Set environment variable", "export [VAR=value]", shell_export}, 119 {"export", "Set environment variable", "export [VAR=value]", shell_export},
122 {"unset", "Unset environment variable", "unset VAR", shell_unset}, 120 {"unset", "Unset environment variable", "unset VAR", shell_unset},
121 {NULL, NULL, NULL, NULL}
122};
123
124/* Table of built-in functions */
125static struct builtInCommand bltins_forking[] = {
126 {"env", "Print all environment variables", "env", shell_env},
127 {"pwd", "Print current directory", "pwd", shell_pwd},
123 {".", "Source-in and run commands in a file", ". filename", shell_source}, 128 {".", "Source-in and run commands in a file", ". filename", shell_source},
124 {"help", "List shell built-in commands", "help", shell_help}, 129 {"help", "List shell built-in commands", "help", shell_help},
125 {NULL, NULL, NULL, NULL} 130 {NULL, NULL, NULL, NULL}
@@ -247,6 +252,9 @@ static int shell_help(struct job *cmd, struct jobSet *junk)
247 for (x = bltins; x->cmd; x++) { 252 for (x = bltins; x->cmd; x++) {
248 fprintf(stdout, "%s\t%s\n", x->cmd, x->descr); 253 fprintf(stdout, "%s\t%s\n", x->cmd, x->descr);
249 } 254 }
255 for (x = bltins_forking; x->cmd; x++) {
256 fprintf(stdout, "%s\t%s\n", x->cmd, x->descr);
257 }
250 fprintf(stdout, "\n\n"); 258 fprintf(stdout, "\n\n");
251 return TRUE; 259 return TRUE;
252} 260}
@@ -743,6 +751,13 @@ static int runCommand(struct job newJob, struct jobSet *jobList, int inBg)
743 nextout = 1; 751 nextout = 1;
744 } 752 }
745 753
754 /* Match any built-ins here */
755 for (x = bltins; x->cmd; x++) {
756 if (!strcmp(newJob.progs[i].argv[0], x->cmd)) {
757 return (x->function(&newJob, jobList));
758 }
759 }
760
746 if (!(newJob.progs[i].pid = fork())) { 761 if (!(newJob.progs[i].pid = fork())) {
747 signal(SIGTTOU, SIG_DFL); 762 signal(SIGTTOU, SIG_DFL);
748 763
@@ -760,7 +775,7 @@ static int runCommand(struct job newJob, struct jobSet *jobList, int inBg)
760 setupRedirections(newJob.progs + i); 775 setupRedirections(newJob.progs + i);
761 776
762 /* Match any built-ins here */ 777 /* Match any built-ins here */
763 for (x = bltins; x->cmd; x++) { 778 for (x = bltins_forking; x->cmd; x++) {
764 if (!strcmp(newJob.progs[i].argv[0], x->cmd)) { 779 if (!strcmp(newJob.progs[i].argv[0], x->cmd)) {
765 exit (x->function(&newJob, jobList)); 780 exit (x->function(&newJob, jobList));
766 } 781 }