diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-09-14 21:20:13 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-09-14 21:20:13 +0200 |
commit | b7bedab28a4ce16b722386852d39f0ad7d524d41 (patch) | |
tree | 512f2a1427fcb28b3579137ebb4ddb8fb97291c8 | |
parent | e1481dcb4227066974aeee49fcb349ae5c0eee4a (diff) | |
download | serenity-b7bedab28a4ce16b722386852d39f0ad7d524d41.zip |
Shell: Support extremely naive shell script execution
This patch allows passing a script as an argument to the Shell program.
We will read the specified line by line and pass them through the Shell
command interpreter.
This is not very powerful, but it's a start :^)
-rw-r--r-- | Shell/main.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Shell/main.cpp b/Shell/main.cpp index 57acffdd6e..19bdf37284 100644 --- a/Shell/main.cpp +++ b/Shell/main.cpp @@ -360,6 +360,9 @@ static int run_command(const String& cmd) if (cmd.is_empty()) return 0; + if (cmd.starts_with("#")) + return 0; + auto commands = Parser(cmd).parse(); #ifdef SH_DEBUG @@ -642,6 +645,21 @@ int main(int argc, char** argv) return 0; } + if (argc == 2 && argv[1][0] != '-') { + CFile file(argv[1]); + if (!file.open(CIODevice::ReadOnly)) { + fprintf(stderr, "Failed to open %s: %s\n", file.filename().characters(), file.error_string()); + return 1; + } + for (;;) { + auto line = file.read_line(4096); + if (line.is_null()) + break; + run_command(String::copy(line, Chomp)); + } + return 0; + } + { auto* cwd = getcwd(nullptr, 0); g.cwd = cwd; |