create an automator quick action to enable creation of tar archives using tar command on macOS

I want to create an automator quick action to enable creation of tar archives using tar command on macOS on any selected file or folder in finder. Do I have to use Shell Script or something else? I am unable to do it. Someone please help.

I am unable to run the following script for creating tar files. Getting error message.


Tarfile="$1.tar"
count=1
cd "${@%/*}"
if [ $# -eq 1 ]; then 
  while [ -e "$Tarfile" ]
  do
    let count++
    Tarfile="$1 $count.tar"
  done
else 
  Tarfile="Archive.tar"
  while [ -e "$Tarfile" ]
  do
    let count++
    Tarfile="Archive $count.tar"
  done
fi
/usr/bin/tar -chf "$Tarfile" "${@##*/}"

create an automator quick action to enable creation of tar archives using tar command on macOS
 
 
Q