Skip to content

Commit de68e2e

Browse files
SaraTahir28cyf
authored andcommitted
Implementing cat with process.argv-node feature to access what user types in terminal.
1 parent 407b010 commit de68e2e

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

  • implement-shell-tools/cat

implement-shell-tools/cat/cat.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import process from "node:process"
2+
import {promises as fs} from "node:fs"
3+
4+
5+
const argv = process.argv.slice(2)
6+
if (argv.length != 1) {
7+
console.error(`Expected exactly 1 argument (a path) to be passed but got ${argv.length}.`);
8+
process.exit(1);
9+
}
10+
11+
const path = argv[0]
12+
const content = await fs.readFile(path, "utf-8")
13+
console.log(content)

0 commit comments

Comments
 (0)