summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2007-09-24 12:06:52 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2007-09-24 12:06:52 +0200
commitb0615cc9096be1d2ed2813af3a0d850e1009b9d4 (patch)
tree9a129175642164213bdecfbe6295441e1cd7e60f
parent14b5c2a647924440444977806c72b8ee6f586e26 (diff)
downloadbarebox-b0615cc9096be1d2ed2813af3a0d850e1009b9d4.tar.gz
barebox-b0615cc9096be1d2ed2813af3a0d850e1009b9d4.tar.xz
- add 'source' command
- add help text for 'source' and 'sh'
-rw-r--r--common/hush.c48
1 files changed, 44 insertions, 4 deletions
diff --git a/common/hush.c b/common/hush.c
index 7301d8aa5c..ddd797ce39 100644
--- a/common/hush.c
+++ b/common/hush.c
@@ -272,7 +272,7 @@ static char *insert_var_value(char *inp);
static const char *get_local_var(const char *var);
static int set_local_var(const char *s, int flg_export);
static int execute_script(const char *path, int argc, char *argv[]);
-
+static int source_script(const char *path, int argc, char *argv[]);
static int b_check_space(o_string *o, int len)
{
@@ -1446,6 +1446,17 @@ int run_command (const char *cmd, int flag)
static int execute_script(const char *path, int argc, char *argv[])
{
+ int ret;
+
+ env_push_context();
+ ret = source_script(path, argc, argv);
+ env_pop_context();
+
+ return ret;
+}
+
+static int source_script(const char *path, int argc, char *argv[])
+{
struct p_context ctx;
char *script;
int ret;
@@ -1457,9 +1468,7 @@ static int execute_script(const char *path, int argc, char *argv[])
if (!script)
return 1;
- env_push_context();
ret = parse_string_outer(&ctx, script, FLAG_PARSE_SEMICOLON);
- env_pop_context();
free(script);
@@ -1488,7 +1497,9 @@ static int do_sh(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
}
static __maybe_unused char cmd_sh_help[] =
-"write me\n";
+"Usage: sh filename [arguments]\n"
+"\n"
+"Execute a shell script\n";
U_BOOT_CMD_START(sh)
.maxargs = CONFIG_MAXARGS,
@@ -1496,3 +1507,32 @@ U_BOOT_CMD_START(sh)
.usage = "run shell script",
U_BOOT_CMD_HELP(cmd_sh_help)
U_BOOT_CMD_END
+
+static int do_source(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+{
+ if (argc < 2) {
+ printf ("Usage:\n%s\n", cmdtp->usage);
+ return 1;
+ }
+
+ return source_script(argv[1], argc - 1, argv + 1);
+}
+
+static char *source_aliases[] = { ".", NULL};
+
+static __maybe_unused char cmd_source_help[] =
+"Usage: . filename [arguments]\n"
+"or source filename [arguments]\n"
+"\n"
+"Read and execute commands from filename in the current shell\n"
+"environment and return the exit status of the last command exe-\n"
+"cuted from filename\n";
+
+U_BOOT_CMD_START(source)
+ .maxargs = CONFIG_MAXARGS,
+ .aliases = source_aliases,
+ .cmd = do_source,
+ .usage = "execute shell script in current shell environment",
+ U_BOOT_CMD_HELP(cmd_source_help)
+U_BOOT_CMD_END
+