\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 :)

Comments

Popular posts from this blog

'jasypt.encryptor.password' or one of ['jasypt.encryptor.privateKeyString', 'jasypt.encryptor.privateKeyLocation'] must be provided for Password-based or Asymmetric encryption

Field or property 'jobParameters' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext' - Spring Batch

Couldn't store job: Unable to serialize JobDataMap for insertion into database because the value of property 'jobLauncher' is not serializable