I need to find the encrypted(.enc) files from a folder and decrypt them.
I will find the .enc files
if [[ -n "$(ls -A /sodaman/tempPrabhu/temp/*.enc 2>/dev/null)" ]]; then
And I used enc_files=($( ls *.enc )) but it takes all the files as one and fails. It considers all the files for the output as one line. So I replaced it with mapfile to decrypt the files one by one but it throws an error
test.sh: line 31: syntax error near unexpected token `<' test.sh: line 31: `  mapfile -t enc_files < <(ls *.enc)'
Below is the script:
if [[ -n "$(ls -A /sodaman/tempPrabhu/temp/*.enc 2>/dev/null)" ]]; then
  #create array of encrypted files
  mapfile -t enc_files < <(ls *.enc)
  enc_files=($( ls *.enc ))
  #echo Creating array $enc_files
  
  #decrypt all encrypted files.
  echo Creating loop for encryped files
  for m in "${enc_files[@]}"
  do
  d=$(echo "$m" | cut -f 1 -d '.')
  echo $d
  d=$d.dat
  echo $d
  /empty/extproc/hfencrypt_plus $m $d Decrypt /empty/extproc/hfsymmetrickey.dat log.log infa91punv
  echo /empty/extproc/hfencrypt_plus $m $d Decrypt /empty/extproc/hfsymmetrickey.dat log.log infa91punv
  if [[ -f "$d" ]]; then
      mv $m /empty/sodaman/tempPrabhu/blr_temp
      #echo Moving file to encrypted archive : mv "$m" /empty/sodaman/enc_archive
      echo removing log file : rm log.log
      rm log.log
  else
      echo File was not decrypted successfully
  fi
  done
fi
 
     
     
    