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 ./test_bash.sh ./test_bash.sh: line 6: syntax error near unexpected token `list.txt' ./test_bash.sh: line 6: ` done < cat list.txt'
On 23/07/2020 15: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.txtdone < list.txt> > ./test_bash.sh > ./test_bash.sh: line 6: syntax error near unexpected token `list.txt' > ./test_bash.sh: line 6: ` done < cat list.txt' > _______________________________________________ > CentOS mailing list > CentOS at centos.org > https://lists.centos.org/mailman/listinfo/centos-- Giles Coochey
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.txtYou 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.
Sorry - I see it now "remove the cat". Thanks "All" for the suggestions. I wasnt aware of the method to avoid the cut command. Jerry
On Thu, 2020-07-23 at 10:49 -0400, Jerry Geis wrote:> Sorry - I see it now "remove the cat". > > Thanks "All" for the suggestions.??I wasnt aware of the method to > avoid the > cut command. >Here's a few "historical" observations on this thread. 1) ?Your original script looks like you were trying to write to the syntax of the old Bourne ( sometimes called "boring" ) shell. ?In the olden days of Unix in the 20th century, that was the ONE shell you could reliably expect to be present on the target machine. 2) ?You are now using Bash ( Bourne-Again SHell ) which is obviously an evolutionary development and is much more capable. ?It has SO much more capabilities that ( as others have pointed out ) it can do many things with internal functions that used to require other tools ( "cat", "expr", others ) to accomplish. 3) ?You write scripts in a similar fashion to the way I do it. ?Plenty of whoopsies and typos along the way to debug. ?Since I'm now an old geezer from the prehistoric times of Unix, I still stick to the old thumb rule "The man page is your friend" that some people seem to be forgetting these days. Just my $0.02 (US) worth.> Jerry > _______________________________________________ > CentOS mailing list > CentOS at centos.org > https://lists.centos.org/mailman/listinfo/centos-- Ron Loftin reloftin at twcny.rr.com "God, root, what is difference ?" Piter from UserFriendly