Solved

Scripts in Cygwin acting strangely

Posted on 2007-03-20
4
314 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

I use more than 1 computer in my office for various reasons. Multiple keyboards and mice take up more than just extra space, they make working a little more complicated. Using one mouse and keyboard for all of my computers makes life easier. This co…
Healthcare organizations in the United States must adhere to the guidance of both the HIPAA (Health Insurance Portability and Accountability Act) and HITECH (Health Information Technology for Economic and Clinical Health Act) for securing and protec…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Viewers will learn how to use the Hootsuite Dashboard.

773 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