File tree 3 files changed +43
-1
lines changed
3 files changed +43
-1
lines changed Original file line number Diff line number Diff line change @@ -13,4 +13,8 @@ A collection of simple bash scripts.
13
13
2 . [ Square a number] ( scripts/squarenumber.sh ) : A simple function that squares an integer
14
14
15
15
## $RANDOM
16
- 1 . [ Guess number] ( scripts/guess-number-game.sh ) : User should guess a number from 1 to 100
16
+ 1 . [ Guess number] ( scripts/guess-number-game.sh ) : User should guess a number from 1 to 100
17
+
18
+ ## Reading files
19
+ 1 . [ File reader] ( scripts/read-line-by-line.sh ) : The script prints the file content line-by-line
20
+ 2 . [ Multiple files reader] ( scripts/read-files.sh ) : Prints the content of all files given by arguments
Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+ # Lucas Saito, 2021/04/09
3
+ # Usage: bash read-files.sh file1 file2 file3 ...
4
+ #
5
+ # Given "n" arguments(files), the script reads
6
+ # each file's content line-by-line.
7
+
8
+
9
+ if [[ $# -eq 0 ]]; then
10
+ echo " [read-lines]: No arguments were given"
11
+ exit 0
12
+ else
13
+ counter=1
14
+ for file in $@ ; do
15
+ echo " [read-lines]: Reading file [$counter /$# ]: $file "
16
+ while read line; do
17
+
18
+ echo $line
19
+ done < $file
20
+ counter=$(( counter+ 1 ))
21
+ done
22
+ fi
23
+ exit 0
Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+ # Lucas Saito, 2021/04/09
3
+ # Given a file by command line argument,
4
+ # the script will read its content line-by-line
5
+
6
+ if [[ $# -eq 0 ]]; then
7
+ echo " No file was inputted"
8
+ exit 0
9
+ else
10
+ echo " Reading file: $1 "
11
+ while read line; do
12
+ echo $line
13
+ done < $1
14
+ fi
15
+ exit 0
You can’t perform that action at this time.
0 commit comments