0

I have a script that will create 3 files.

keyword1script.sh

keyword2script.sh

keyword3script.sh

In each file i would like to see the following

cat keyword1script.sh
filekeyword11
filekeyword12
filekeyword13
filekeyword14

cat keyword2script.sh
filekeyword11
filekeyword12
filekeyword13
filekeyword14
filekeyword15
filekeyword16

cat keyword3script.sh
filekeyword11
filekeyword12

How ever what I am getting:

cat keyword1script.sh
filekeyword11
filekeyword12
filekeyword13
filekeyword14

cat keyword2script.sh
filekeyword11
filekeyword12
filekeyword13
filekeyword14

cat keyword3script.sh
filekeyword11
filekeyword12
filekeyword13
filekeyword14

I have tried changing some parts of the code around and different types of looping however all yield the same result.

#!/bin/bash

findwords=( keyword1 keyword2 keyword3 )
files=( 4 7 2 )

for t in "${findwords[@]}"
do
END=( "${files[@]}" )
  for i in $(seq 1 $END)
  do
  echo "" >> ${t}script.sh
  echo "file${t}$i" >> ${t}script.sh
  done
done

The first loop seems to working fine, files keyword1script.sh, keyword1script.sh, and keyword1script.sh are created however each file contains the same amount of rows.

The END variable should change once the first loop is done to the second number in the array files.

Scoder12
  • 25
  • 3
  • 7
Donna Delour
  • 117
  • 3
  • 3
    Try running the script under `set -xv` to see what's going on. – choroba Apr 12 '19 at 19:25
  • 3
    `t` is a string. `files` is not an associative array. So `${files[t]}` is not doing what you think it is. – William Pursell Apr 12 '19 at 19:26
  • @WilliamPursell thank you for pointing that out, I updated the question and changed END=( "${files[t]}" ) to END=( "${files[@]}" ) I have tried so many different things I am going in circles. – Donna Delour Apr 12 '19 at 19:36

0 Answers0