From 6ad7491300081104243891c6a80eb8076cac7b90 Mon Sep 17 00:00:00 2001 From: apio Date: Sat, 3 Jun 2023 16:59:18 +0200 Subject: [PATCH] sh: Skip comments (and shebangs!) --- apps/sh.cpp | 4 ++++ initrd/sbin/mount-tmpfs | 2 ++ 2 files changed, 6 insertions(+) diff --git a/apps/sh.cpp b/apps/sh.cpp index e51a6f9e..d998fcd2 100644 --- a/apps/sh.cpp +++ b/apps/sh.cpp @@ -23,6 +23,8 @@ static Result> split_command_into_args(StringView cmd) static Result execute_command(StringView command) { + if (strcspn(command.chars(), " #") == 0) return {}; + auto args = TRY(split_command_into_args(command)); if (args.size() < 1) exit(0); @@ -94,6 +96,8 @@ Result luna_main(int argc, char** argv) if (strspn(cmd.chars(), " \n") == cmd.length()) continue; + if (strcspn(cmd.chars(), " #") == 0) continue; + if (!strncmp(cmd.chars(), "cd", 2)) { auto args = TRY(split_command_into_args(cmd.view())); diff --git a/initrd/sbin/mount-tmpfs b/initrd/sbin/mount-tmpfs index 46a3740c..7625ebd7 100644 --- a/initrd/sbin/mount-tmpfs +++ b/initrd/sbin/mount-tmpfs @@ -1,3 +1,5 @@ +#!/bin/sh + mkdir -p /tmp mount -t tmpfs /tmp chmod 1777 /tmp