Linked Questions
10 questions linked to/from What does `while read -r line || [[ -n $line ]]` mean?
333
votes
7
answers
323k
views
What's the point in adding a new line to the end of a file?
Some compilers (especially C or C++ ones) give you warnings about:
No new line at end of file
I thought this would be a C-programmers-only problem, but github displays a message in the commit view:
\...
9
votes
4
answers
9k
views
Bash Read: Reading comma separated list, last element is missed
The output of the command below is weird to me. Why does it not give me back element 5?
$ echo '0,1,2,3,4,5' | while read -d, i; do echo $i; done
0
1
2
3
4
I would expect '5' to be returned as well. ...
11
votes
3
answers
4k
views
For what purpose does "read" exit 1 when EOF is encountered?
The bash man page says the following about the read builtin:
The exit status is zero, unless end-of-file is encountered
This recently bit me because I had the -e option set and was using the ...
3
votes
4
answers
817
views
Logical all/any in bash
I want to run a series of tests (each on a different PID), and derive a successful status only if all tests exit successfully. Something like
check $PID1 && check $PID2 && check $PID3
...
5
votes
2
answers
519
views
Iterating over the contents of a file
I understand that the output of file.txt is treated as input for the next command in the pipe. Yet, I don't understand how while in conjuction with read traverses the file from one line to the next?
...
0
votes
3
answers
2k
views
How to iterate over top 5 lines from a file with bash?
I can iterate over the lines of a file this way:
while read l; do echo $l; done < file
Is there a way to iterate over only the top 5 lines?
0
votes
1
answer
7k
views
How to read multiple variables from a file
Example File
oj Orange Juice
10 100
A half gallon of orange juice.
This is what I did and it worked
while read -r simpleName itemName; do
read currentQuantity maximumQuantity
read ...
1
vote
1
answer
2k
views
How to read file in bash using a fixed number of character?
So, i'm using bash to read a file (that has no newlines, space or tab).
Something like this:
aababcbbcbckqkkqkqhddhkehkjhqkjhsdk
skjhqkdjhqkzdhkzhdkjqzhdhqkjhzdkqzh
though there is a newline in this ...
0
votes
1
answer
446
views
While loop issue (not reading the last line )
hello i have below issue in the while loop , it is not reading last line .
while IFS= read -r line
do
echo $line
done<file_ref_col_master.txt
input file
FILE_ID~col_POS~...
0
votes
2
answers
79
views
Why the sed command is not replacing the pattern inside a shell script?
I am trying to prepare a shell script to include several chained sed commands.
I am using /bin/sh in FreeBSD 12. Which seems to be POSIX compliant (see man page here).
This is what I have tried, it ...