Re: Off Topic bash question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



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.
_______________________________________________
CentOS mailing list
CentOS@xxxxxxxxxx
https://lists.centos.org/mailman/listinfo/centos



[Index of Archives]     [CentOS]     [CentOS Announce]     [CentOS Development]     [CentOS ARM Devel]     [CentOS Docs]     [CentOS Virtualization]     [Carrier Grade Linux]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Linux USB]


  Powered by Linux