Skip to content

Commit d8c098f

Browse files
committed
fix cat
1 parent 287fd3a commit d8c098f

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

implement-shell-tools/cat/cat.mjs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ program.parse();
1313
const options = program.opts();
1414
const paths = program.args;
1515

16+
const numNonBlank = options.b;
17+
const numAll = !!options.n && !numNonBlank;
18+
1619
let hadError = false;
1720
for(const path of paths){
1821
let content;
@@ -29,14 +32,14 @@ for(const path of paths){
2932
let lineNum = 1;
3033

3134
for (const line of lines){
32-
if(options.b){
35+
if(numNonBlank){
3336
if(line.trim() !== ""){
3437
console.log(`${lineNum.toString().padStart(5)} ${line}`)
3538
lineNum++;
3639
} else {
3740
console.log("");
3841
}
39-
} else if(options.n){
42+
} else if(numAll){
4043
console.log(`${lineNum.toString().padStart(5)} ${line}`)
4144
lineNum++;
4245
} else{

0 commit comments

Comments
 (0)