delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2007/10/25/13:05:16

X-Recipient: archive-cygwin AT delorie DOT com
X-Spam-Check-By: sourceware.org
From: "Dave Korn" <dave DOT korn AT artimi DOT com>
To: <cygwin AT cygwin DOT com>
References: <E4EA239D9BC4F84A984FE6C7F115EE7F02742E3E AT mpexch3 DOT nt DOT ingenuity DOT com>
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
X-Mailer: Microsoft Office Outlook 11
In-Reply-To: <E4EA239D9BC4F84A984FE6C7F115EE7F02742E3E@mpexch3.nt.ingenuity.com>
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
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<end-of-line>

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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019