[CentOS] Off Topic bash question

Thu Jul 23 14:48:25 UTC 2020
Anand Buddhdev <anandb at ripe.net>

On 23/07/2020 16:37, Jerry Geis wrote:

> Thanks, when I change it do the following I get a syntax error
> #!/bin/bash
> #
> while read LINE
> do
>           echo $LINE
> done < cat list.txt

You don't use "cat" here; it's not needed at all. You write:

done < list.txt

This tells the shell to redirect the stdin of the while loop from the 
file "list.txt".

People in the unix world have made a mess of code everywhere by 
superfluously using "cat". In the old usenet days, anyone who posted 
shell code with unnecessary use of cat used to be awarded a prize (and 
it was not something to be proud of, but to be embarrassed about).

"cat" is short for "concatenate", and for that purpose, it is perfect. 
When you want to take two or more sources of data, and combine them, 
then cat is the perfect tool, eg:

cat file1 file2 file3 > combined-file

But for most other tasks, if you're using "cat", then you're almost 
certainly misusing it. For example, people who do:

cat file | grep something

This makes the shell fork and run cat, and then the shell has to setup a 
pipe to pass the data to grep. Too much overhead. They don't know that 
they can just do:

grep something file

and let the grep command read the file itself.