Simple Bash scripting

bashcygwin;

I'm trying to get to grips with Bash scripting via Cygwin. My script is about as simple as it gets.

I change the directory to the root of my C drive, and print the new location.

#!/usr/bin/bash 
cd /cygdrive/c
pwd

is saved in the file chdir.sh in my home directory.
I then call ./chdir.sh from the bash prompt. This results in the error

: No such file or directorygdrive/c
/cygdrive/c/Documents and Settings/rcotton

I definitely have a C drive, and the command cd /cygdrive/c works when I call it directly from the bash prompt.

I realise that this problem is likely stupidly simple; please can you tell me what I'm doing wrong.

Best Answer

Just in case you have edited your script with an editor which is not part of the Cygwin environment (e.g., anything like 'Notepad*', 'WordPad', etc.): convert your script to Unix-lineendings via the 'dos2unix' tool.

The script itself is absolutely correct, no need for any / or \ changes. The error message

: No such file or directorygdrive/c

leads me to think of problems with the lineending since \r\n (Windows line ending). Just in case you do not have 'dos2unix' installed:

tr -d \\r < win.txt > unix.txt

or

sed -e 's/$/\r/' < unix.txt > win.txt