diff --git a/implement-shell-tools/cat/cat.js b/implement-shell-tools/cat/cat.js new file mode 100644 index 000000000..5eb942126 --- /dev/null +++ b/implement-shell-tools/cat/cat.js @@ -0,0 +1,14 @@ +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); +const theNumberOfLines = content.split("\n").length; +console.log(`The number of lines in the file is ${theNumberOfLines}.`); \ No newline at end of file