0

I have the following bashscript below. My goal is to itterate over multiple files in the directory. The name of the files will be batch_1, batch_2, batch_3, batch_4, etc. There should be no more than 7 batches.

I have the following script below.

files=( $(echo 1) )
declare -p files
declare -a files=([0]="batch_")
for data in ${files[@]}
do
  cat ${data} | cut -d , -f2,3 | grep -v "IP" > data_ip_${data}
done

However, when I run this I receive the error zsh: bad subscript for direct array assignment: 0

Does any know what can cause this specifically with my script? Or possible solutions? Any advice may help.

Lam
  • 1

1 Answers1

0

Are you running this with bash, or with zsh? You've tagged this with bash, but your question mentions a zsh error.

  • Like ksh, bash arrays start from zero.
  • zsh arrays start from one (unless you have the KSH_ARRAYS variable set). See man zshparam and search for Array Subscripts
cas
  • 78,579