Split the filename based upon delimiter is giving syntax error: unexpected "(" (expecting "done") in bash/sh

Viewed 134

Looping in the current directory and checking if the file extension ends with yaml, then split the filename on dot and perform other operations. Below is my code.

What's wrong here? I'm getting error like: syntax error: unexpected "(" (expecting "done")

for fname in $(find . -name '*.yaml' -exec basename {} \;); do
  echo "Printing filename $fname"
  ARR=(${fname//./ })
  echo "${ARR[0]}"
done
1 Answers

This script may be able to meet your needs:

for fname in *.yaml; do
  echo "Printing filename $fname"
  ARR[i]=`echo $fname | sed 's/\..*//'`
  echo "${ARR[i]}"
  i=$i+1;
done
Related