Xiphias Xiphias - 7 months ago 36
Bash Question

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

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

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?


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