for files in $(find . -maxdepth 1 -type f); do
echo $(basename $files)
done
Works when its copy/inserted into the console, but when ran as a shell script, it returns
'/TEST.sh: line 1: syntax error near unexpected token `do
'/TEST.sh: line 1: `for files in $(find . -maxdepth 1 -type f); do
EDIT:
Attempt 2 with #!/bin/sh added to the first line now results
-bash: /oper/text2pdf_TEST.sh: /bin/sh^M: bad interpreter: No such file or directory
However /bin/sh does exist
Attempt 3 with #!/bin/bash added to the first line now results
-bash: /oper/text2pdf_TEST.sh: /bin/bash^M: bad interpreter: No such file or directory
However /bin/bash does exist
Your error is the big hint: Notice that it wants to say
but the closing tick is at the beginning of the line. That’s because the token it’s printing is
do^M(dofollowed by a carriage return).You probably edited the file in a DOS/Windows style editor. It needs to have UNIX style line endings.