X-Recipient: archive-cygwin AT delorie DOT com X-Spam-Check-By: sourceware.org From: "Dave Korn" To: References: Subject: RE: Unable to access file from shell script (XP configure problem?) Date: Thu, 25 Oct 2007 18:04:50 +0100 Message-ID: <005401c81729$27e20140$2e08a8c0@CAM.ARTIMI.COM> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 11 In-Reply-To: Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com On 25 October 2007 17:52, Ramon Felciano wrote: > Specifically, shell scripts don't appear to be able to read files based > on filenames passed in as commandline parameters. Heh. Actually, shell scripts are entirely able to read files, based on any filename you pass in whatsoever - ... > felciano AT DURFELCIANO2 /cygdrive/c/Downloads > $ ./buggy.sh /cygdrive/c/Downloads/ramon.txt > Hello /cygdrive/c/Downloads/ramon.txt >> No such file or directoryramon.txt > Bye! > > felciano AT DURFELCIANO2 /cygdrive/c/Downloads ... - even filenames with a CR in them. And bash correctly reports that you do not have a file called "cygdrive/c/Downloads/ramon.txt^M" on your disk, although that ^M (CR with no LF) causes the error message to overwrite itself a bit. > There are no spaces in the filename and I'm using POSIX paths, so I > don't think that's the issue. I can clearly find and view the file from > the commandline so I don't think it is an access control or volume mount > problem in the Cygwin environment. The shell script itself sees the > command-line parameter (echo works) but the subsequent cat command fails > with a "No such file or directory" error. The thing that looks > particular odd is the error message: > > ---------------------------------------------------- >> No such file or directoryramon.txt > ---------------------------------------------------- > > which looks like it is an error message that overwrote the > "/cygdrive/c/Downloads/ramon.txt" pathname. CR at the end. That's the definitive symptom. > Any suggestions on where to hunt further for a resolution? Where did the CR actually come from? It came from here: $ cat buggy.sh #!/bin/sh echo Hello "$@" cat "$@" ^^^^^ If you've got CRLF lineendings in that script, that line actually looks bash (which, being unixy, only expects LF line endings) like this: cat "$@"^M so once $@ is substituted (and quote removal applied), you have: cat /cygdrive/c/Downloads/ramon.txt^M The solution is to run d2u on buggy.sh, or don't use notepad/wordpad to create it, use vi/emacs/any other editor that can generate LF-only line endings. Also, see any of the recent release ANNOUNCEments in the cygwin-announce list archive for a couple of other options (set -oo igncr etc.). cheers, DaveK -- Can't think of a witty .sigline today.... -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/