Wednesday, June 17, 2015

\r command not found. Cygwin script

You might have faced this error when creating a cygwin script, Even a simple script can replicate this issue

#!/bin/sh
date
who
ls
ps ax

./deploy.sh
./deploy.sh: line 2: $'date\r': command not found
./deploy.sh: line 3: $'who\r': command not found

https://cygwin.com/ml/cygwin-announce/2010-08/msg00015.html

This page has the problem in detail.So the solution is

#!/bin/sh
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
(set -o igncr) 2>/dev/null && set -o igncr; # this comment is needed
date
who
ls
ps ax


This line does the trick. Happy Cygwin scripting :)

No comments:

Post a Comment