0

Context

Catalina (zsh) & Homebrew: man pages return successfully for pdftk & ps2pdf

The goal is to execute: pdfBatesStamp.sh as described in https://unix.stackexchange.com/a/115537/182280

I changed the first line of the script to: #!/bin/zsh -

Observations

Preliminary test returned:

enter image description here

The error: : command not foundine XX: are lines with no commands / comments. Screenshot shows lines 104,105,109,111 are null:

enter image description here

UPDATE: said error is remedied by placing a # at the start of the line.

Line 132:

enter image description here

Questions

  1. What exactly is causing said errors?
  2. What is the remedy?
  3. Is there any reason that this script will NEVER run in said context?

For jsbillings

user@JUPITER pdfBatesStamp % ./pdfBatesStamp.sh Exhibits_ActivityReport.pdf
./pdfBatesStamp.sh:59: command not found: ^M
./pdfBatesStamp.sh:132: parse error near `elif'
user@JUPITER pdfBatesStamp % 
user@JUPITER pdfBatesStamp % sh pdfBatesStamp.sh Exhibits_ActivityReport.pdf
pdfBatesStamp.sh: line 132: syntax error near unexpected token `elif'
'dfBatesStamp.sh: line 132: `elif [ $# -eq 2 ]; then

Ubuntu 16.04 Test results:

user@azimuth:~/Desktop/BatesStamp$ cp pdfBatesStamp.sh test.sh
user@azimuth:~/Desktop/BatesStamp$ dos2unix test.sh
dos2unix: converting file test.sh to Unix format ...
user@azimuth:~/Desktop/BatesStamp$ ls
Exhibits_ActivityReport.pdf  pdfBatesStamp.sh  test.sh
user@azimuth:~/Desktop/BatesStamp$ ls -l
total 11384
-rw------- 1 user user 11589045 Nov 23 18:00 Exhibits_ActivityReport.pdf
-rwxrwxr-x 1 user user    32764 Nov 23 22:24 pdfBatesStamp.sh
-rwxrwxr-x 1 user user    32764 Nov 23 22:26 test.sh
user@azimuth:~/Desktop/BatesStamp$ ./test.sh Exhibits_ActivityReport.pdf 
Input File = "/home/user/Desktop/BatesStamp/Exhibits_ActivityReport.pdf"  (origSize=11,589,045)
(standard_in) 1: syntax error
(standard_in) 1: illegal character: M
(standard_in) 1: syntax error
(standard_in) 1: syntax error
(standard_in) 1: syntax error
./test.sh: line 384: [: too many arguments
*** Can't find page size
user@azimuth:~/Desktop/BatesStamp$ mac2unix test.sh
mac2unix: converting file test.sh to Unix format ...
user@azimuth:~/Desktop/BatesStamp$ ./test.sh Exhibits_ActivityReport.pdf 
Input File = "/home/user/Desktop/BatesStamp/Exhibits_ActivityReport.pdf"  (origSize=11,589,045)
(standard_in) 1: syntax error
(standard_in) 1: illegal character: M
(standard_in) 1: syntax error
(standard_in) 1: syntax error
(standard_in) 1: syntax error
./test.sh: line 384: [: too many arguments
*** Can't find page size
gatorback
  • 1,216
  • 20
  • 44
  • 1
    run `dos2unix` and/or `mac2unix` on the file and try again. Sounds like you have some bad line endings. – jesse_b Nov 24 '21 at 02:22
  • 1
    Did you install bash? Why are you running a bash script with /bin/sh? – jsbillings Nov 24 '21 at 02:27
  • @jsbillings I do not think I installed bash. `./pdfBatesStamp.sh.sh Exhibits_ActivityReport.pdf` returned errors so I tried `sh pdfBatesStamp.sh.sh Exhibits_ActivityReport.pdf` – gatorback Nov 24 '21 at 02:37
  • What errors did the bash command return? And if you could update your question, please use text and not hard to read pictures. – jsbillings Nov 24 '21 at 02:40
  • @jsbillings Please see eponymous section of OP: is this the information requested? I think Catalina uses zsh and I changed the first line of the script to `#!/bin/zsh -` – gatorback Nov 24 '21 at 02:53
  • So is your question how to convert a bash script to zsh? You are still running it in POSIX shell compatibility mode, so really the question is how to convert it to POSIX sh. – jsbillings Nov 24 '21 at 02:56
  • A lot of these errors look like you didn’t clean up the dos new lines. I agree with the other commenter on using `dos2unix`. – jsbillings Nov 24 '21 at 03:00
  • @jsbillings. I agree and felt that the newline, CR was the culprit so I ran `dos2unix` on Ubuntu16.04 and posted the results. Not what I had hoped for \ expected – gatorback Nov 24 '21 at 03:33

0 Answers0