I'm trying to rename csv files in my subdirectory based on the name of the subdirectory while also adding \_1.csv. For example: filename\_1.csv, filename\_2.csv for each file in a subdirectory.

I wrote a bash script but it doesn't give me the correct output.

```
#!/bin/bash
num=1
parent=/whois/v10_cctlds/full/
newfolder=/whois/csv7/
mkdir "$newfolder"
for folder in "$parent"/*; do
  if [[ -d "$folder" ]]; then
    foldername="${folder##*/}"
    for file in "$parent"/"$foldername"/*; do
      filename="${file##*/}"
      newfilename="$(foldername $num).csv"
      cp "$file" "$newfolder"/"$newfilename"
    done
  fi
done

```