Linked Questions

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: \...
Philipp Stephan's user avatar
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. ...
Karel's user avatar
  • 1,518
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 ...
jesse_b's user avatar
  • 41.5k
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 ...
alexis's user avatar
  • 5,869
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? ...
0binny0's user avatar
  • 59
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?
sbmthakur's user avatar
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 ...
PioneerRaptor's user avatar
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 ...
secemp9's user avatar
  • 2,502
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~...
daturm girl's user avatar
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 ...
M.E.'s user avatar
  • 631