Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Scripts in Cygwin acting strangely

Posted on 2007-03-20
4
315 Views
Last Modified: 2013-11-15
Bash scripting in my Cygwin environment that used to work so well is now acting strangely.

To illustrate see how variable $i works with echo but fails with ls, given a file like this...
$ cat /tmp/psif
pointsec
pointsec/docs
pointsec/docs/Architecture.doc

And a script like this...
$ cat /tmp/ww
#!/usr/bin/bash -x
for i in `cat /tmp/psif`
do
echo $i
ls -dl $i
read x
done

When I run it with -x for debgging I get this....
$ /tmp/ww
++ cat /tmp/psif
+ for i in '`cat /tmp/psif`'
+ echo $'pointsec\r'
pointsec
+ ls -dl $'pointsec\r'
: No such file or directory
+ read x

+ for i in '`cat /tmp/psif`'
+ echo $'pointsec/docs\r'
pointsec/docs
+ ls -dl $'pointsec/docs\r'
: No such file or directorydocs
+ read x

+ for i in '`cat /tmp/psif`'
+ echo $'pointsec/docs/Architecture.doc\r'
pointsec/docs/Architecture.doc
+ ls -dl $'pointsec/docs/Architecture.doc\r'
: No such file or directorydocs/Architecture.doc
+ read x

Anyone have an idea what's going on?
0
Comment
Question by:veedar
  • 2
4 Comments
 
LVL 29

Expert Comment

by:MikeOM_DBA
ID: 18758150

Yes, the directory you are trying to 'ls' does not exist in the path from wich you are executing the script.

"No such file or directory docs/Architecture.doc"

0
 
LVL 15

Author Comment

by:veedar
ID: 18758315
I wish it was that easy...they do exist...

$ ls -ld pointsec pointsec/docs pointsec/docs/Architecture.doc
drwxr-xr-x+ 4 veedar Domain Users      0 Mar 19 13:30 pointsec
drwxr-xr-x+ 2 veedar Domain Users      0 Mar 16 10:48 pointsec/docs
-rwxr-xr-x  1 veedar Domain Users 128512 Mar 13 10:37 pointsec/docs/Architecture.doc
0
 
LVL 58

Accepted Solution

by:
amit_g earned 500 total points
ID: 18758478
/tmp/psif is created using a DOS editor and has \r in the end. Do

dos2unix /tmp/psif

and then use your same script.
0
 
LVL 15

Author Comment

by:veedar
ID: 18758667
Thanks amit_g dos2unix fixed it.  I thought I had already checked for a DOS issue but I guess not.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A list of useful business intelligence software.
All of the resources available today make learning a new digital media easier than ever-- if you know where to begin. This is a clear, simple guide to a few of the basic digital art mediums and how to begin learning them on your own.
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…
The viewer will learn how to successfully download and install the SARDU utility on Windows 8, without downloading adware.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question