Why does this multi-line shell script not work using cygwin, although in one line it works?

StackOverflow https://stackoverflow.com/questions/23241862

  •  08-07-2023
  •  | 
  •  

Pregunta

I use cygwin for Windows to run shell scripts. My script changes umlauts to LaTeX equivalents. It works.

I run the script via:

sh umlauts.sh
pause

This is my sed command, which perfectly works.

/usr/bin/find -name \*.tex | xargs -I p sed -i 's/ü/{\\"u}/g' p

However, running it twice in the same file leads to an error:

/usr/bin/find -name \*.tex | xargs -I p sed -i 's/ü/{\\"u}/g' p
/usr/bin/find -name \*.tex | xargs -I p sed -i 's/ä/{\\"a}/g' p

I get:

: no such file or directory.tex

Which looks like a strangely formatted message, as .tex is the ending of my file and should not be part of the error message.

This is probably a very trivial error. Why can't I write multiple lines of code into my script and run it successfully?

¿Fue útil?

Solución

Your script was written with a DOS editor and contains \r\n line endings. *nix (including cygwin) uses \n line endings, so the \r character remains at the end of the sed p command.

See if you have dos2unix available, or run this command on the script

sed 's/\r$//' umlauts.sh

Otros consejos

Also avoid spaces after the backslash \ (trailing spaces), somehow it causes problems with my Cygwin. Luckily I did not have to use Windows after 2016.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top