I have a script that will try to extract the file's base name and then I do additional work with it. Only when using this script with a file with this naming convention (including spaces and characters - not really sure what's triggering the error), do I get the basename extra operand error.
The file name: JERASH - XZ 837367432.pdf
Here the script once executed generates error:
filetimestamp=$(date "+%F-%T")
timenow=$(date -u)
for file in files/input/*
do
printf "Break 1 \n"
#filename no extension:
filenamenopath=$(basename $file)
filenamenoext=${filenamenopath%.pdf}
printf "Break 2 \n"
#check if file is pdf
printf "File Name with No Path:" $filenamenopath
printf "Break 3 \n"
And here is the error:
Break 1 basename: extra operand ‘XZ’