summaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
authorBernard Xiong <[email protected]>2016-04-18 13:53:32 +0800
committerBernard Xiong <[email protected]>2016-04-18 13:53:32 +0800
commit838141e89f87dd6f5b378734c1601b2aaed93f05 (patch)
treedb2594d7d27d6636b830ba0e1c67412ee5597d18 /components
parent43f68131ce64fbb4c3e476e684f3d06919ebd5af (diff)
[finsh] Add echo command for msh.
Diffstat (limited to 'components')
-rw-r--r--components/finsh/msh_cmd.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/components/finsh/msh_cmd.c b/components/finsh/msh_cmd.c
index 99ca82f55d..29a30eabe6 100644
--- a/components/finsh/msh_cmd.c
+++ b/components/finsh/msh_cmd.c
@@ -252,6 +252,35 @@ int cmd_mkfs(int argc, char **argv)
}
FINSH_FUNCTION_EXPORT_ALIAS(cmd_mkfs, __cmd_mkfs, format disk with file system);
+int cmd_echo(int argc, char** argv)
+{
+ if (argc == 2)
+ {
+ rt_kprintf("%s\n", argv[1]);
+ }
+ else if (argc == 3)
+ {
+ int fd;
+
+ fd = open(argv[2], O_RDWR | O_APPEND | O_CREAT, 0);
+ if (fd >= 0)
+ {
+ write (fd, argv[1], strlen(argv[1]));
+ close(fd);
+ }
+ else
+ {
+ rt_kprintf("open file:%s failed!\n", argv[2]);
+ }
+ }
+ else
+ {
+ rt_kprintf("Usage: echo \"string\" [filename]\n");
+ }
+
+ return 0;
+}
+FINSH_FUNCTION_EXPORT_ALIAS(cmd_echo, __cmd_echo, echo string to file);
#endif
#ifdef RT_USING_LWIP