From cd7ccde118a77556fa763b67f7a6628aceca30aa Mon Sep 17 00:00:00 2001 From: Zobeir-Rigi Date: Sat, 18 Apr 2026 02:13:17 +0100 Subject: [PATCH 1/2] Add cat.js --- implement-shell-tools/cat/cat.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 implement-shell-tools/cat/cat.js diff --git a/implement-shell-tools/cat/cat.js b/implement-shell-tools/cat/cat.js new file mode 100644 index 000000000..38a33e6f8 --- /dev/null +++ b/implement-shell-tools/cat/cat.js @@ -0,0 +1,12 @@ +import process from "node:process"; +import { promises as fs } from "node:fs"; + +const argv = process.argv.slice(2); +if (argv.length != 1) { + console.error(`Expected exactly 1 argument (a path) to be passed but got ${argv.length}.`); + process.exit(1); +} +const path = argv[0]; +const content = await fs.readFile(path, "utf-8"); + +console.log(content); \ No newline at end of file From 699913aa3273786771b2b62e2830f41c6ad8372c Mon Sep 17 00:00:00 2001 From: Zobeir-Rigi Date: Sat, 18 Apr 2026 13:38:25 +0100 Subject: [PATCH 2/2] we need to split the string by the /n, and then get the length --- implement-shell-tools/cat/cat.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/implement-shell-tools/cat/cat.js b/implement-shell-tools/cat/cat.js index 38a33e6f8..5eb942126 100644 --- a/implement-shell-tools/cat/cat.js +++ b/implement-shell-tools/cat/cat.js @@ -9,4 +9,6 @@ if (argv.length != 1) { const path = argv[0]; const content = await fs.readFile(path, "utf-8"); -console.log(content); \ No newline at end of file +console.log(content); +const theNumberOfLines = content.split("\n").length; +console.log(`The number of lines in the file is ${theNumberOfLines}.`); \ No newline at end of file