Skip to content

Commit c4f47a0

Browse files
committed
code for cat folder to print content of 1 and all files
1 parent 132d7cd commit c4f47a0

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

  • implement-shell-tools/cat

implement-shell-tools/cat/cat.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import argparse
2+
import os
3+
4+
parser = argparse.ArgumentParser(description="Python implementation of cat command")
5+
6+
parser.add_argument("files", nargs="+", help="Files to read")
7+
8+
args = parser.parse_args()
9+
10+
line_number = 1
11+
12+
for file in args.files:
13+
if not os.path.isfile(file):
14+
print(f"cat: {file}: No such file or directory")
15+
continue
16+
17+
18+
with open(file, "r") as f:
19+
for line in f:
20+
print(line, end ="")

0 commit comments

Comments
 (0)