Re: [CentOS] Off Topic bash question

2020-07-23 Thread Ron Loftin
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

Re: [CentOS] Off Topic bash question

2020-07-23 Thread Jerry Geis
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 ___ CentOS mailing list CentOS@centos.org https://lists.centos.org/mailman/listinfo/centos

Re: [CentOS] Off Topic bash question

2020-07-23 Thread Anand Buddhdev
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

Re: [CentOS] Off Topic bash question

2020-07-23 Thread Giles Coochey
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.txt done < list.txt ./test_bash.sh ./test_bash.sh: line 6: syntax error near unexpected token `list.txt'

Re: [CentOS] Off Topic bash question

2020-07-23 Thread Gianluca Cecchi
On Thu, Jul 23, 2020 at 4:25 PM Anand Buddhdev wrote: > On 23/07/2020 15:46, Jerry Geis wrote: > > Hi Jerry, > > See below, inline, for some comments. > > > > while read -r LINE > > do > > NODENAME=` echo $LINE | cut -f 1 -d ','` > > NODENAME=$(cut -d, -f1 <<< $LINE) > > Notes: use $( instead

Re: [CentOS] Off Topic bash question

2020-07-23 Thread Anand Buddhdev
On 23/07/2020 15:46, Jerry Geis wrote: Hi Jerry, You can do even better: index=0 total=0 names=() ip=() IFS=, while read -r NODENAME IP do names[$index]="$NODENAME" ip[$((index++))]="$IP" ((total++)) done < list.txt In this example, you set the input field separator (IFS) to the

Re: [CentOS] Off Topic bash question

2020-07-23 Thread Jerry Geis
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'

Re: [CentOS] Off Topic bash question

2020-07-23 Thread Pierre Malard
Hi, Some remarks: - just try « expr ${VAR} + 1 » (with blanc between car) - use simple redirection (« < ») with a simple reference to file (« done < list.txt ») - use « ${VAR} » to manage variables - you can use numeric notation to increment VAR (p.e. « total=$(( ${total} + 1 )) ») An other

Re: [CentOS] Off Topic bash question

2020-07-23 Thread Anand Buddhdev
On 23/07/2020 15:46, Jerry Geis wrote: Hi Jerry, See below, inline, for some comments. I have a simple script: #!/bin/bash # index=0 total=0 names=() ip=() while read -r LINE do NODENAME=` echo $LINE | cut -f 1 -d ','` NODENAME=$(cut -d, -f1 <<< $LINE) Notes: use $( instead of backticks.

[CentOS] Off Topic bash question

2020-07-23 Thread Jerry Geis
I have a simple script: #!/bin/bash # index=0 total=0 names=() ip=() while read -r LINE do NODENAME=` echo $LINE | cut -f 1 -d ','` IP=` echo $LINE | cut -f 2 -d ','` names[index]="$NODENAME" ip[index]="$IP" index=`expr index+1` total=`expr total+1` done <<< $(cat list.txt) simple file: